├── .clang-format ├── .github └── workflows │ ├── build_android.yml │ ├── build_linux.yml │ ├── build_web.yml │ ├── build_windows.yml │ ├── group_builds.yml │ ├── lint.yml │ └── runner.yml ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── SConstruct ├── demo ├── addons │ └── utility_ai │ │ ├── bin │ │ └── libutilityai.gdextension │ │ └── icons │ │ ├── UtilityAIAction.svg │ │ ├── UtilityAIActionGroup.svg │ │ ├── UtilityAIAgent.svg │ │ ├── UtilityAIArea2DVisibilitySensor.svg │ │ ├── UtilityAIArea3DVisibilitySensor.svg │ │ ├── UtilityAIBTAgent.svg │ │ ├── UtilityAIBTCooldownTicks.svg │ │ ├── UtilityAIBTCooldownTime.svg │ │ ├── UtilityAIBTNodeReference.svg │ │ ├── UtilityAIBTParallel.svg │ │ ├── UtilityAIBTPassBy.svg │ │ ├── UtilityAIBTPassThrough.svg │ │ ├── UtilityAIBTRandomSelector.svg │ │ ├── UtilityAIBTRandomSequence.svg │ │ ├── UtilityAIBTRepeater.svg │ │ ├── UtilityAIBTRunNQSQuery.svg │ │ ├── UtilityAIBTScoreBasedPicker.svg │ │ ├── UtilityAIBTSelector.svg │ │ ├── UtilityAIBTSequence.svg │ │ ├── UtilityAIBehaviour.svg │ │ ├── UtilityAIBehaviourGroup.svg │ │ ├── UtilityAIBehaviourTreeNodes.svg │ │ ├── UtilityAIBooleanConsideration.svg │ │ ├── UtilityAIBooleanSensor.svg │ │ ├── UtilityAIConsideration.svg │ │ ├── UtilityAIConsiderationGroup.svg │ │ ├── UtilityAICustomPropertyConsideration.svg │ │ ├── UtilityAIDefault.svg │ │ ├── UtilityAIDistanceVector2Sensor.svg │ │ ├── UtilityAIDistanceVector3Sensor.svg │ │ ├── UtilityAIFloatRangeSensor.svg │ │ ├── UtilityAIIntRangeSensor.svg │ │ ├── UtilityAIPointGridSearchSpace.svg │ │ ├── UtilityAISearchCriteria.svg │ │ ├── UtilityAISearchSpaces.svg │ │ ├── UtilityAISensor.svg │ │ ├── UtilityAISensorGroup.svg │ │ ├── UtilityAIStateTreeNode.svg │ │ └── UtilityAIStateTreeNodes.svg ├── icon.svg └── project.godot ├── doc_classes ├── UtilityAI.xml ├── UtilityAIAction.xml ├── UtilityAIActionGroup.xml ├── UtilityAIActions.xml ├── UtilityAIAgent.xml ├── UtilityAIAngleToVector2SearchCriterion.xml ├── UtilityAIAngleToVector3SearchCriterion.xml ├── UtilityAIAngleToVector3XZSearchCriterion.xml ├── UtilityAIAngleVector2Sensor.xml ├── UtilityAIAngleVector3Sensor.xml ├── UtilityAIArea2DSearchSpace.xml ├── UtilityAIArea2DVisibilitySensor.xml ├── UtilityAIArea3DSearchSpace.xml ├── UtilityAIArea3DVisibilitySensor.xml ├── UtilityAIBTCompositeNodes.xml ├── UtilityAIBTCooldownMsec.xml ├── UtilityAIBTCooldownTicks.xml ├── UtilityAIBTCooldownUsec.xml ├── UtilityAIBTDecoratorNodes.xml ├── UtilityAIBTFixedResult.xml ├── UtilityAIBTInverter.xml ├── UtilityAIBTLeaf.xml ├── UtilityAIBTLimiter.xml ├── UtilityAIBTNodeReference.xml ├── UtilityAIBTParallel.xml ├── UtilityAIBTPassBy.xml ├── UtilityAIBTPassThrough.xml ├── UtilityAIBTRandomSelector.xml ├── UtilityAIBTRandomSequence.xml ├── UtilityAIBTRepeatUntil.xml ├── UtilityAIBTRepeater.xml ├── UtilityAIBTRoot.xml ├── UtilityAIBTRunNQSQuery.xml ├── UtilityAIBTScoreBasedPicker.xml ├── UtilityAIBTSelector.xml ├── UtilityAIBTSequence.xml ├── UtilityAIBTTaskNodes.xml ├── UtilityAIBehaviour.xml ├── UtilityAIBehaviourGroup.xml ├── UtilityAIBehaviourTreeNodes.xml ├── UtilityAIBehaviours.xml ├── UtilityAIBooleanConsideration.xml ├── UtilityAIBooleanSensor.xml ├── UtilityAIConsideration.xml ├── UtilityAIConsiderationGroup.xml ├── UtilityAIConsiderationGroupResource.xml ├── UtilityAIConsiderationResource.xml ├── UtilityAIConsiderationResources.xml ├── UtilityAIConsiderations.xml ├── UtilityAICustomPropertyConsideration.xml ├── UtilityAICustomSearchCriterion.xml ├── UtilityAIDebuggerOverlay.xml ├── UtilityAIDistanceToNode2DSearchCriterion.xml ├── UtilityAIDistanceToNode3DSearchCriterion.xml ├── UtilityAIDistanceToVector2SearchCriterion.xml ├── UtilityAIDistanceToVector3SearchCriterion.xml ├── UtilityAIDistanceVector2Sensor.xml ├── UtilityAIDistanceVector3Sensor.xml ├── UtilityAIDotProductToPositionVector2SearchCriterion.xml ├── UtilityAIDotProductToPositionVector3SearchCriterion.xml ├── UtilityAIDotProductVector2SearchCriterion.xml ├── UtilityAIDotProductVector3SearchCriterion.xml ├── UtilityAIFloatRangeSensor.xml ├── UtilityAIIntRangeSensor.xml ├── UtilityAIMetadataSearchCriterion.xml ├── UtilityAINQSSearchCriteria.xml ├── UtilityAINQSSearchSpaces.xml ├── UtilityAINodeChildrenSearchSpace.xml ├── UtilityAINodeGroupSearchSpace.xml ├── UtilityAINodeQuerySystem.xml ├── UtilityAIPerformanceMonitorSingleton.xml ├── UtilityAIPointGrid2DSearchSpace.xml ├── UtilityAIPointGrid3DSearchSpace.xml ├── UtilityAISTNode.xml ├── UtilityAISTRoot.xml ├── UtilityAISensor.xml ├── UtilityAISensorGroup.xml ├── UtilityAISensors.xml └── UtilityAIStateTreeNodes.xml ├── src ├── agent_behaviours │ ├── action.cpp │ ├── action.h │ ├── action_group.cpp │ ├── action_group.h │ ├── actions.cpp │ ├── actions.h │ ├── agent.cpp │ ├── agent.h │ ├── behaviour.cpp │ ├── behaviour.h │ ├── behaviour_group.cpp │ ├── behaviour_group.h │ ├── behaviours.cpp │ ├── behaviours.h │ ├── consideration.cpp │ ├── consideration.h │ ├── consideration_group.cpp │ ├── consideration_group.h │ ├── considerations.cpp │ ├── considerations.h │ ├── considerations │ │ ├── boolean.cpp │ │ ├── boolean.h │ │ ├── custom_property.cpp │ │ └── custom_property.h │ ├── sensor.cpp │ ├── sensor.h │ ├── sensor_group.cpp │ ├── sensor_group.h │ ├── sensors.cpp │ ├── sensors.h │ └── sensors │ │ ├── angle_vector2.cpp │ │ ├── angle_vector2.h │ │ ├── angle_vector3.cpp │ │ ├── angle_vector3.h │ │ ├── area2d_visibility.cpp │ │ ├── area2d_visibility.h │ │ ├── area3d_visibility.cpp │ │ ├── area3d_visibility.h │ │ ├── boolean.cpp │ │ ├── boolean.h │ │ ├── distance_vector2.cpp │ │ ├── distance_vector2.h │ │ ├── distance_vector3.cpp │ │ ├── distance_vector3.h │ │ ├── float_range.cpp │ │ ├── float_range.h │ │ ├── int_range.cpp │ │ └── int_range.h ├── behaviour_tree │ ├── composite_nodes.cpp │ ├── composite_nodes.h │ ├── cooldown_msec.cpp │ ├── cooldown_msec.h │ ├── cooldown_ticks.cpp │ ├── cooldown_ticks.h │ ├── cooldown_usec.cpp │ ├── cooldown_usec.h │ ├── decorator_nodes.cpp │ ├── decorator_nodes.h │ ├── definitions.h │ ├── fixed_result.cpp │ ├── fixed_result.h │ ├── inverter.cpp │ ├── inverter.h │ ├── leaf.cpp │ ├── leaf.h │ ├── limiter.cpp │ ├── limiter.h │ ├── node_reference.cpp │ ├── node_reference.h │ ├── nodes.cpp │ ├── nodes.h │ ├── parallel.cpp │ ├── parallel.h │ ├── pass_by.cpp │ ├── pass_by.h │ ├── pass_through.cpp │ ├── pass_through.h │ ├── random_selector.cpp │ ├── random_selector.h │ ├── random_sequence.cpp │ ├── random_sequence.h │ ├── repeat_until.cpp │ ├── repeat_until.h │ ├── repeater.cpp │ ├── repeater.h │ ├── root.cpp │ ├── root.h │ ├── run_nqs_query.cpp │ ├── run_nqs_query.h │ ├── score_based_picker.cpp │ ├── score_based_picker.h │ ├── selector.cpp │ ├── selector.h │ ├── sequence.cpp │ ├── sequence.h │ ├── task_nodes.cpp │ └── task_nodes.h ├── debugger │ ├── debugger_inspector.h │ ├── debugger_overlay.cpp │ ├── debugger_overlay.h │ ├── debugger_plugin.cpp │ └── debugger_plugin.h ├── editor │ ├── editor_plugin.cpp │ └── editor_plugin.h ├── gen │ └── doc_data.gen.cpp ├── node_query_system │ ├── node_query_system.cpp │ ├── node_query_system.h │ ├── search_criteria │ │ ├── angle_to_vector2.cpp │ │ ├── angle_to_vector2.h │ │ ├── angle_to_vector3.cpp │ │ ├── angle_to_vector3.h │ │ ├── angle_to_vector3_xz.cpp │ │ ├── angle_to_vector3_xz.h │ │ ├── custom.cpp │ │ ├── custom.h │ │ ├── distance_to_node2d.cpp │ │ ├── distance_to_node2d.h │ │ ├── distance_to_node3d.cpp │ │ ├── distance_to_node3d.h │ │ ├── distance_to_vector2.cpp │ │ ├── distance_to_vector2.h │ │ ├── distance_to_vector3.cpp │ │ ├── distance_to_vector3.h │ │ ├── dot_product_to_position_vector2.cpp │ │ ├── dot_product_to_position_vector2.h │ │ ├── dot_product_to_position_vector3.cpp │ │ ├── dot_product_to_position_vector3.h │ │ ├── dot_product_vector2.cpp │ │ ├── dot_product_vector2.h │ │ ├── dot_product_vector3.cpp │ │ ├── dot_product_vector3.h │ │ ├── metadata.cpp │ │ ├── metadata.h │ │ ├── nqs.cpp │ │ └── nqs.h │ └── search_spaces │ │ ├── area2d.cpp │ │ ├── area2d.h │ │ ├── area3d.cpp │ │ ├── area3d.h │ │ ├── node_children.cpp │ │ ├── node_children.h │ │ ├── node_group.cpp │ │ ├── node_group.h │ │ ├── nqs.cpp │ │ ├── nqs.h │ │ └── point_grid │ │ ├── point_grid_2d.cpp │ │ ├── point_grid_2d.h │ │ ├── point_grid_3d.cpp │ │ └── point_grid_3d.h ├── performance_monitor_singleton.cpp ├── performance_monitor_singleton.h ├── register_types.cpp ├── register_types.h ├── resources │ └── considerations │ │ ├── consideration_group_resource.cpp │ │ ├── consideration_group_resource.h │ │ ├── consideration_resource.cpp │ │ ├── consideration_resource.h │ │ ├── consideration_resources.cpp │ │ └── consideration_resources.h ├── state_tree │ ├── node.cpp │ ├── node.h │ ├── nodes.cpp │ ├── nodes.h │ ├── root.cpp │ └── root.h ├── utility_ai.cpp └── utility_ai.h └── utility_ai.png /.github/workflows/build_linux.yml: -------------------------------------------------------------------------------- 1 | name: Build Linux 2 | on: 3 | workflow_dispatch: 4 | workflow_call: 5 | 6 | jobs: 7 | build: 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | include: 12 | - precision: double 13 | arch: x86_64 14 | platform: linux 15 | target-type: template_debug 16 | - precision: double 17 | arch: x86_64 18 | platform: linux 19 | target-type: template_release 20 | 21 | # Taken mostly from https://github.com/godotengine/godot-cpp-template/blob/main/.github/workflows/builds.yml 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@v4 26 | with: 27 | submodules: true 28 | fetch-depth: 0 29 | 30 | # Setup dependencies 31 | - name: Setup godot-cpp 32 | uses: ./godot-cpp/.github/actions/setup-godot-cpp 33 | with: 34 | platform: ${{ matrix.platform }} 35 | em-version: 3.1.62 36 | 37 | # Build GDExtension (with caches) 38 | - name: Cache .scons_cache 39 | uses: actions/cache@v4 40 | with: 41 | path: ${{ github.workspace }}/.scons-cache/ 42 | key: ${{ matrix.platform }}_${{ matrix.arch }}_${{ matrix.precision }}_${{ matrix.target-type }}_cache 43 | 44 | - name: Build GDExtension 45 | shell: sh 46 | env: 47 | SCONS_CACHE: ${{ github.workspace }}/.scons-cache/ 48 | run: | 49 | scons target=${{ matrix.target-type }} platform=${{ matrix.platform }} arch=${{ matrix.arch }} precision=${{ matrix.precision }} 50 | 51 | - name: Upload Artifact 52 | uses: actions/upload-artifact@v4 53 | with: 54 | name: libutilityai-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.precision }}-${{ matrix.target-type }} 55 | path: ${{ github.workspace }}/demo/addons/utility_ai/bin/*.so 56 | if-no-files-found: error 57 | -------------------------------------------------------------------------------- /.github/workflows/build_web.yml: -------------------------------------------------------------------------------- 1 | name: Build Web 2 | on: 3 | workflow_dispatch: 4 | workflow_call: 5 | 6 | jobs: 7 | build: 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | include: 12 | - precision: double 13 | arch: wasm32 14 | platform: web 15 | target-type: template_debug 16 | - precision: double 17 | arch: wasm32 18 | platform: web 19 | target-type: template_release 20 | 21 | # Taken mostly from https://github.com/godotengine/godot-cpp-template/blob/main/.github/workflows/builds.yml 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout 25 | uses: actions/checkout@v4 26 | with: 27 | submodules: true 28 | fetch-depth: 0 29 | 30 | # Setup dependencies 31 | - name: Setup godot-cpp 32 | uses: ./godot-cpp/.github/actions/setup-godot-cpp 33 | with: 34 | platform: ${{ matrix.platform }} 35 | em-version: 3.1.62 36 | 37 | # Build GDExtension (with caches) 38 | - name: Cache .scons_cache 39 | uses: actions/cache@v4 40 | with: 41 | path: ${{ github.workspace }}/.scons-cache/ 42 | key: ${{ matrix.platform }}_${{ matrix.arch }}_${{ matrix.precision }}_${{ matrix.target-type }}_cache 43 | 44 | - name: Build GDExtension 45 | shell: sh 46 | env: 47 | SCONS_CACHE: ${{ github.workspace }}/.scons-cache/ 48 | run: | 49 | scons target=${{ matrix.target-type }} platform=${{ matrix.platform }} arch=${{ matrix.arch }} precision=${{ matrix.precision }} 50 | 51 | - name: Upload Artifact 52 | uses: actions/upload-artifact@v4 53 | with: 54 | name: libutilityai-${{ matrix.platform }}-${{ matrix.arch }}-${{ matrix.precision }}-${{ matrix.target-type }} 55 | path: ${{ github.workspace }}/demo/addons/utility_ai/bin/*.wasm 56 | if-no-files-found: error 57 | -------------------------------------------------------------------------------- /.github/workflows/group_builds.yml: -------------------------------------------------------------------------------- 1 | name: Build Linux 2 | on: 3 | workflow_dispatch: 4 | workflow_call: 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v4 12 | with: 13 | submodules: true 14 | fetch-depth: 0 15 | 16 | - name: Download Build artifacts 17 | uses: actions/download-artifact@v4 18 | with: 19 | path: ${{ github.workspace }}/demo/addons/utility_ai/bin/ 20 | merge-multiple: true 21 | 22 | - name: Delete Build artifacts 23 | uses: geekyeggo/delete-artifact@v5 24 | with: 25 | name: libutilityai-* 26 | 27 | - name: Upload Artifact 28 | uses: actions/upload-artifact@v4 29 | with: 30 | name: utility_ai_demo_project 31 | path: ${{ github.workspace }}/demo/ 32 | if-no-files-found: error 33 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | on: 3 | workflow_dispatch: 4 | workflow_call: 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - name: Check out code 12 | uses: actions/checkout@v4 13 | - name: Setup clang-format 14 | shell: bash 15 | run: | 16 | python -m pip install clang-format 17 | - name: Run clang-format 18 | shell: bash 19 | run: | 20 | clang-format --style=file:.clang-format --dry-run --Werror $(find "src/" | grep -E ".*(\.cpp|\.h)$") -------------------------------------------------------------------------------- /.github/workflows/runner.yml: -------------------------------------------------------------------------------- 1 | name: Builds 2 | 3 | on: 4 | workflow_dispatch: 5 | pull_request: 6 | push: 7 | 8 | jobs: 9 | lint: 10 | uses: ./.github/workflows/lint.yml 11 | build_android: 12 | needs: [lint] 13 | uses: ./.github/workflows/build_android.yml 14 | # build_ios: 15 | # needs: [lint] 16 | # uses: ./.github/workflows/build_ios.yml 17 | build_linux: 18 | needs: [lint] 19 | uses: ./.github/workflows/build_linux.yml 20 | build_windows: 21 | needs: [lint] 22 | uses: ./.github/workflows/build_windows.yml 23 | build_web: 24 | needs: [lint] 25 | uses: ./.github/workflows/build_web.yml 26 | group_builds: 27 | needs: [build_android, build_linux, build_windows, build_web] 28 | uses: ./.github/workflows/group_builds.yml -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "godot-cpp"] 2 | path = godot-cpp 3 | url = https://github.com/godotengine/godot-cpp.git 4 | branch = 4.3 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 JarkkoPar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIAction.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIActionGroup.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIAgent.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIArea2DVisibilitySensor.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIArea3DVisibilitySensor.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTCooldownTicks.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTCooldownTime.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTNodeReference.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTParallel.svg: -------------------------------------------------------------------------------- 1 | 2 | 14 | 16 | 34 | 43 | 52 | 53 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTPassBy.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTPassThrough.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTRandomSequence.svg: -------------------------------------------------------------------------------- 1 | 2 | 14 | 16 | 35 | 44 | 45 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTRepeater.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTRunNQSQuery.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTScoreBasedPicker.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTSelector.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBTSequence.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBehaviour.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBehaviourGroup.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBehaviourTreeNodes.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBooleanConsideration.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIBooleanSensor.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIConsideration.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIConsiderationGroup.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAICustomPropertyConsideration.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIDefault.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIDistanceVector2Sensor.svg: -------------------------------------------------------------------------------- 1 | 2 | 14 | 16 | 34 | 38 | 43 | 48 | 49 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIDistanceVector3Sensor.svg: -------------------------------------------------------------------------------- 1 | 2 | 14 | 16 | 34 | 39 | 44 | 45 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIFloatRangeSensor.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIIntRangeSensor.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIPointGridSearchSpace.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAISearchCriteria.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAISearchSpaces.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAISensor.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAISensorGroup.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIStateTreeNode.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/addons/utility_ai/icons/UtilityAIStateTreeNodes.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /demo/project.godot: -------------------------------------------------------------------------------- 1 | ; Engine configuration file. 2 | ; It's best edited using the editor UI and not directly, 3 | ; since the parameters that go here are not all obvious. 4 | ; 5 | ; Format: 6 | ; [section] ; section goes between [] 7 | ; param=value ; assign values to parameters 8 | 9 | config_version=5 10 | 11 | [application] 12 | 13 | config/name="UtilityAI Demo" 14 | config/features=PackedStringArray("4.3", "GL Compatibility") 15 | config/icon="res://icon.svg" 16 | 17 | [rendering] 18 | 19 | renderer/rendering_method="gl_compatibility" 20 | -------------------------------------------------------------------------------- /doc_classes/UtilityAI.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | There are four main node groups in Utility AI GDExtension: Agent behaviours, Behaviour Tree, State Tree, and the Node Query System (NQS). All are utility-based systems for implementing robust AI systems to your games. 7 | The Agent behaviours, Utility enabled State Tree and Utility enabled Behaviour Tree focus on defining behaviours for AI agents. They answer the question "What is the best behaviour for the current situation?". Use these nodes when you want to choose what an AI should do. 8 | The Node Query System focuses on using utility functions to score and filter any type of Godot nodes. They answer the question "What is the best node for the job?". Use the NQS when you want to choose the best tile to move to, the biggest threat to attack, the best healing item to consume, for example. 9 | 10 | 11 | 12 | 13 | 14 | This property can be used to include or exlude the node from processing. 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIActions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Base node for [UtilityAIAction] and [UtilityAIActionGroup]. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Use this property only to let the AI agent know when the chosen action has failed. You will also need to set the [member is_finished] property! The stepper function will immediately set it back to [code]false[/code] once it has handled the failed event. 13 | 14 | 15 | Use this property only to let the AI agent know when the chosen action is finished. The stepper function will immediately set it back to [code]false[/code] once it has moved on to the next action. 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIAngleToVector2SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based on the node minimum and maximum angle compared to the set [member angle_to_direction_vector]. 5 | 6 | 7 | The [Vector2] angle search criterion can be used to score and filter based on the node minimum and maximum angle compared to the set [member angle_to_direction_vector]. The search space direction is the (1,0) vector rotated by the global rotation amount. 8 | 9 | 10 | 11 | 12 | 13 | The direction vector compare the search space node facing to. 14 | 15 | 16 | Maximum angle in degrees. If the angle is more than this and filtering is applied, the tested node is filtered out. 17 | 18 | 19 | Minimum angle in degrees. If the angle is less than this and filtering is applied, the tested node is filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIAngleToVector3SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based on the node minimum and maximum angle compared to the set [member angle_to_direction_vector]. 5 | 6 | 7 | The [Vector3] angle search criterion can be used to score and filter based on the node minimum and maximum angle compared to the set [member angle_to_direction_vector]. The search space direction is the [code]-global_transform.basis.z[/code] vector rotated by the global rotation amount. 8 | 9 | 10 | 11 | 12 | 13 | The direction vector compare the search space node facing to. 14 | 15 | 16 | Maximum angle in degrees. If the angle is more than this and filtering is applied, the tested node is filtered out. 17 | 18 | 19 | Minimum angle in degrees. If the angle is less than this and filtering is applied, the tested node is filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIAngleToVector3XZSearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based on the angle on the xz-plane between the search space node direction ([code]-global_transform.basis.z[/code]) compared to the given [member angle_to_direction_vector]. 5 | 6 | 7 | The [Vector3] XZ angle search criterion can be used to score and filter based on the angle on the xz-plane between the search space node direction ([code]-global_transform.basis.z[/code]) compared to the given [member angle_to_direction_vector]. 8 | 9 | 10 | 11 | 12 | 13 | The direction vector compare the search space node facing to. 14 | 15 | 16 | Minimum angle in degrees. If the angle is less than this and filtering is applied, the tested node is filtered out. 17 | 18 | 19 | Maximum angle in degrees. If the angle is more than this and filtering is applied, the tested node is filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIAngleVector3Sensor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Accepts two vectors, calculates the angle between them and scales it to [code]0..1[/code] range. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Input value for the sensor. Base value for the angle calculation, for example the direction of an AI entity. 17 | 18 | 19 | The maximum value for the angle between from and to in degrees, this corresponds to [code]1.0[/code] for the sensor_value. Updates the euler angle automatically. 20 | 21 | 22 | The maximum value for the angle between from and to in radians, this corresponds to [code]1.0[/code] for the sensor_value. Updates the euler angle automatically. 23 | 24 | 25 | Input value for the sensor. The other vector to compare from-vector to, for example direction to closest enemy entity. 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIArea2DSearchSpace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Returns all nodes within an [Area2D] as a search space. 5 | 6 | 7 | This node uses an [Area2D] to define the search space. All the nodes that are within or intersecting with the [Area2D] are returned as the search space. The search space uses the [signal Area2D.on_area_entered] and [signal Area2D.on_area_exited] signals to determine which other [Area2D] nodes are intersecting with the set area. 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | [Area2D] node to use. 28 | 29 | 30 | The areas intersecting or within the set area. Useful when debugging the search space. 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIArea3DSearchSpace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Returns all nodes within an [Area3D] as a search space. 5 | 6 | 7 | This node uses an [Area3D] to define the search space. All the nodes that are within or intersecting with the [Area3D] are returned as the search space. The search space uses the [signal Area3D.on_area_entered] and [signal Area3D.on_area_exited] signals to determine which other [Area3D] nodes are intersecting with the set area. 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | [Area3D] node to use. 28 | 29 | 30 | The areas intersecting or within the set area. Useful when debugging the search space. 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTCompositeNodes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTCooldownMsec.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Sets a branch of the behaviour tree into an x millisecond cooldown after it has been ticked. 5 | 6 | 7 | The cooldown nodes can be used to set a branch of the behaviour tree into a cooldown after it has been ticked. When the cooldown node is ticked, it ticks its child node, starts the cooldown and returns what ever the child node returned. It will return the set [member cooldown_return_value] until the cooldown expires. 8 | 9 | 10 | 11 | 12 | 13 | The cooldown period in milliseconds after the cooldown node is ticked. 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTCooldownTicks.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Sets a branch of the behaviour tree into an x number of ticks cooldown after it has been ticked. 5 | 6 | 7 | The cooldown nodes can be used to set a branch of the behaviour tree into a cooldown after it has been ticked. When the cooldown node is ticked, it ticks its child node, starts the cooldown and returns what ever the child node returned. It will return the set [member cooldown_return_value] until the cooldown expires. 8 | 9 | 10 | 11 | 12 | 13 | The result that is returned during cooldown. Can be either [code]-1[/code]=Failure, [code]0[/code]=Running or [code]1[/code]=Success. 14 | 15 | 16 | The cooldown period in ticks after the cooldown node is ticked. 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTCooldownUsec.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Sets a branch of the behaviour tree into an x microsecond cooldown after it has been ticked. 5 | 6 | 7 | The cooldown nodes can be used to set a branch of the behaviour tree into a cooldown after it has been ticked. When the cooldown node is ticked, it ticks its child node, starts the cooldown and returns what ever the child node returned. It will return the set [member cooldown_return_value] until the cooldown expires. 8 | 9 | 10 | 11 | 12 | 13 | The result that is returned during cooldown. Can be either [code]-1[/code]=Failure, [code]0[/code]=Running or [code]1[/code]=Success. 14 | 15 | 16 | 17 | 18 | The cooldown period in microseconds after the cooldown node is ticked. 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTDecoratorNodes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTFixedResult.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ticks the first behaviour tree child node it has and returns its [member fixed_result] property back to its parent. 5 | 6 | 7 | The fixed result node ticks the first behaviour tree child node it has and regardless of what the child returns, the fixed result node returns what ever value you have set as its [member fixed_result] property back to its parent. This node can also be used as a leaf-node. 8 | 9 | 10 | 11 | 12 | 13 | The result that should always be returned. Can be either [code]-1[/code]=Failure, [code]0[/code]=Running or [code]1[/code]=Success. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTInverter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ticks the first behaviour tree child node it has and returns back to its parent the result of the child node, inverted. 5 | 6 | 7 | The inverter node ticks the first behaviour tree child node it has and returns back to its parent the result of the child node, inverted. So success becomes failure, a failure a success. If Running is returned, the inverter returns running back to its parent. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTLeaf.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Used for conditions and actions. You should define your own [code]on_tick()[/code] method where you do your logic. 5 | 6 | 7 | The leaf node is used for conditions and actions. You should define your own [code]on_tick()[/code] method where you do your logic. You can also define the method with the name [code]tick()[/code] but this is only available for backwards compatibility to version 1.4. 8 | You can either return the tick result or set the [member UtilityAIBehaviourTreeNodes.tick_result] property. Examples: 9 | [gdscript] 10 | func on_tick(blackboard: Variant, delta: float) -> int: 11 | return 1 12 | [/gdscript] 13 | [gdscript] 14 | func on_tick(blackboard: Variant, delta: float) -> int: 15 | tick_result = 1 16 | [/gdscript] 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTLimiter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ticks its child for [member max_repeat_times] and then returns -1 (failure) until the node is reset. 5 | 6 | 7 | The limiter node ticks its child for [member max_repeat_times] and then returns -1 (failure) until the node is reset. 8 | 9 | 10 | 11 | 12 | 13 | The maximum times the limiter node can be ticked. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTNodeReference.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Reference any behaviour tree node type anywhere in your scene. 5 | 6 | 7 | The node reference node can be used to reference any behaviour tree node type anywhere in your scene. This gives a lot of flexibility when designing your AI behaviours. 8 | For instance, you can have an AI agent that has a node reference in its behaviour tree for any items it picks up. Each item can then contain a sub behaviour tree that describes how the item can be used by the AI. When the AI picks up an item, the node reference is set to point to the sub-tree within the item node, and immediately the AI agent can use the item. 9 | 10 | 11 | 12 | 13 | 14 | A behaviour tree node. 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTParallel.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Ticks all its child nodes. If any of the nodes returns failure (-1) or running (0), the parallel node returns it back to its parent. 5 | 6 | 7 | The parallel node ticks all its child nodes. If any of the nodes returns failure (-1) or running (0), the parallel node returns it back to its parent. If the child nodes return both failure and running statuses, the running status is returned to the parent node. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTPassBy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Runs a user-defined [code]tick()[/code] method without returning any result value. 5 | 6 | 7 | The PassBy node can be used to run a user-defined [code]tick()[/code] method without returning any result value. The purpose of this node is to allow running any additional logic during a [code]tick()[/code] without affecting the flow of the Behaviour Tree. In essence, the functionality is similar to the [UtilityAIPassThrough] node, but this node can be placed within a sequence, for example. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTPassThrough.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Calls the user-defined tick-method and then calls the tick-method of its child node, returning what ever the child node tick result is. 5 | 6 | 7 | The passthrough node calls the user-defined tick-method and then calls the tick-method of its child node, returning what ever the child node tick result is. If no child node has been defined, it returns what ever you choose for the tick-result. 8 | You can use this node to do preparations for a behaviour tree branch, for instance calculate some angles or distances that all the nodes within a branch will be using and putting them to user_data. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTRandomSelector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Executes its child nodes in a random order until one of them succeeds (returning [code]1[/code]) or all of them fail (returning [code]-1[/code]). 5 | 6 | 7 | This node type is used to create fallbacks. 8 | The [UtilityAIBTRandomSelector] node executes its child nodes in a random order until one of them succeeds (returning [code]1[/code]) or all of them fail (returning [code]-1[/code]). If a child returns running (0) the selector will return running to its parent. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTRandomSequence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Executes its child nodes in a random order until either all of the succeed (returning [code]1[/code]) or one of them fails (returning [code]-1[/code]). 5 | 6 | 7 | This node type is used to create sequences. 8 | The [UtilityAIBTRandomSequence] node executes its child nodes in a random order until either all of the succeed (returning [code]1[/code]) or one of them fails (returning [code]-1[/code]). If a child returns running (0) the sequence will return running to its parent. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTRepeatUntil.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | The RepeatUntil node ticks its child either until the expected_tick_result is returned by its child or [member max_repeat_times]. If [member max_repeat_times] is set to -1, only the expected_tick_result will end the loop. 7 | 8 | 9 | 10 | 11 | 12 | The result that the child node should return to end the loop. Can be either [code]-1[/code]=Failure, [code]0[/code]=Running or [code]1[/code]=Success. 13 | 14 | 15 | The maximum times the limiter node can be ticked. 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTRepeater.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | The Repeater node ticks its child until [member max_repeat_times] is reached. If [member max_repeat_times] is set to -1 the child will be ticked indefinitely. 7 | 8 | 9 | 10 | 11 | 12 | The maximum times the limiter node can be ticked. 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTRoot.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The main node for the Utility AI Behaviour Tree nodes. 5 | 6 | 7 | This is the main node for the Utility AI Behaviour Tree nodes. The root node is ticked to update the state of the behaviour tree. 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | This is the behaviour tree tick-method you should be using to tick the tree. You can provide any [Variant] type as a parameter (usually a node used as an actor or a dictionary used as a blackboard), along with a delta-time. These are passed to all the child nodes of the behaviour tree during ticks. 18 | 19 | 20 | 21 | 22 | 23 | This is the total time in microseconds the call to the [method tick] method used. 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTRunNQSQuery.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Initialites Node Query System queries. They return running until the query has completed. 5 | 6 | 7 | The Run NQS Query node can be used to initialite Node Query System queries. They return running until the query has completed. 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | A node reference to a NQS Search Space node. (Changed from v1.4 node path). 16 | 17 | 18 | The number of results the search should return. Overrides the setting on the search space. 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTScoreBasedPicker.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Evaluates its direct child nodes and calculates a score for each of them based on [UtilityAIConsideration] and [UtilityAIConsiderationGroup] nodes that are set as the childs of them. 5 | 6 | 7 | The score based picker node evaluates its direct child nodes and calculates a score for each of them based on [UtilityAIConsideration] and [UtilityAIConsiderationGroup] nodes that are set as the childs of them. The direct child node with the highest score is chosen and then ticked. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTSelector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Executes its child nodes from top-to-bottom order until one of them succeeds (returning [code]1[/code]) or all of them fail (returning [code]-1[/code]). 5 | 6 | 7 | This node type is used to create fallbacks. 8 | The [UtilityAIBTSelector] node executes its child nodes from top-to-bottom order until one of them succeeds (returning [code]1[/code]) or all of them fail (returning [code]-1[/code]). If a child returns running (0) the selector will return running to its parent. 9 | The [UtilityAIBTRandomSelector] works similarly, it just shuffles the nodes into a random order before ticking them. 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTSequence.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Executes its child nodes from top-to-bottom order until either all of the succeed (returning [code]1[/code]) or one of them fails (returning [code]-1[/code]). 5 | 6 | 7 | This node type is used to create sequences. 8 | The [UtilityAIBTSequence] node executes its child nodes from top-to-bottom order until either all of the succeed (returning [code]1[/code]) or one of them fails (returning [code]-1[/code]). If a child returns running (0) the sequence will return running to its parent. 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBTTaskNodes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBehaviours.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Base node for [UtilityAIBehaviour] and [UtilityAIBehaviourGroup]. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | The score for the behaviour after the behaviour has evaluated its considerations. 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBooleanConsideration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIBooleanSensor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Accepts a boolean value and scales it to [code]0..1[/code] range. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Input value for the sensor. 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIConsiderationGroup.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Aggregates the input from several considerations or consideration groups to create more complex consideration logic. 5 | 6 | 7 | Consideration groups can be used to aggregate the input from several considerations or consideration groups to create more complex consideration logic. You can nest as many consideration groups as you like, and each consideration group may contain any number and combination of child consideration groups or child considerations. 8 | 9 | 10 | 11 | 12 | 13 | A choice of how the considerations and consideration groups that are childs of the node are aggregated. Can be one of the following: Sum:0,Min:1,Max:2,Mean:3,Multiply:4,FirstNonZero:5. 14 | 15 | 16 | This inverts the group score by calculating: [code]score = 1.0 - score[/code]. It is applied after all the child nodes have been evaluated. 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIConsiderationGroupResource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIConsiderationResource.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIConsiderationResources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIConsiderations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Base node for all UtilityAI consideration nodes. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | If this is set to [code]true[/code], the consideration forces the score to be 0.0 and ends the evaluation immediately. 13 | 14 | 15 | The resulting score for the consideration after evaluation. 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc_classes/UtilityAICustomPropertyConsideration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /doc_classes/UtilityAICustomSearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Defines a method [code]apply_criterion()[/code] that will be called to execute the filtering. 5 | 6 | 7 | With the custom search criterion you can define a method [code]apply_criterion()[/code] that will be called to execute the filtering. You need to set the [member UtilityAINQSSearchCriteria.is_filtered] and [member UtilityAINQSSearchCriteria.score] properties in the method. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDebuggerOverlay.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDistanceToNode2DSearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based on minimum and maximum distance to the set [member distance_to] node. 5 | 6 | 7 | The [Node2D] distance search criterion can be used to score and filter based on minimum and maximum distance to the set [member distance_to] node. 8 | 9 | 10 | 11 | 12 | 13 | The path to the node to which you want to compare the distance to. 14 | 15 | 16 | Maximum distance. If the distance is more than this and filtering is applied, the tested node is filtered out. 17 | 18 | 19 | Minimum distance. If the distance is less than this and filtering is applied, the tested node is filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDistanceToNode3DSearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based on minimum and maximum distance to the set [member distance_to] node. 5 | 6 | 7 | The [Node3D] distance search criterion can be used to score and filter based on minimum and maximum distance to the set [member distance_to] node. 8 | 9 | 10 | 11 | 12 | 13 | The path to the node to which you want to compare the distance to. 14 | 15 | 16 | Maximum distance. If the distance is more than this and filtering is applied, the tested node is filtered out. 17 | 18 | 19 | Minimum distance. If the distance is less than this and filtering is applied, the tested node is filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDistanceToVector2SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based on minimum and maximum distance to the set [member distance_to] vector. 5 | 6 | 7 | The [Vector2] distance search criterion can be used to score and filter based on minimum and maximum distance to the set [member distance_to] vector. 8 | 9 | 10 | 11 | 12 | 13 | The global position to compare the search space node distance to. 14 | 15 | 16 | Maximum distance. If the distance is more than this and filtering is applied, the tested node is filtered out. 17 | 18 | 19 | Minimum distance. If the distance is less than this and filtering is applied, the tested node is filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDistanceToVector3SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based on minimum and maximum distance to the set [member distance_to] vector. 5 | 6 | 7 | The [Vector3] distance search criterion can be used to score and filter based on minimum and maximum distance to the set [member distance_to] vector. 8 | 9 | 10 | 11 | 12 | 13 | The global position to compare the search space node distance to. 14 | 15 | 16 | Maximum distance. If the distance is more than this and filtering is applied, the tested node is filtered out. 17 | 18 | 19 | Minimum distance. If the distance is less than this and filtering is applied, the tested node is filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDotProductToPositionVector2SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Checks if a specific position is in front of or behind a search space node. 5 | 6 | 7 | The [Vector2] dot product to position search criterion can be used to check if a specific position is in front of or behind a search space node. It calculates a direction vector using the [member dot_product_position] and the node global position. Then, it calculates a dot product using the direction vector and the search space node direction ([code]Vector2(1,0)[/code] rotated by rotation). 8 | 9 | 10 | 11 | 12 | 13 | The global position to use in the dot product calculation. 14 | 15 | 16 | If filtering is in use, the result given by the dot product is compared to this value for filtering. 17 | 18 | 19 | If filtering is in use, this is the comparison that is done to decide on the filtering. The choices are: "LessThan:0,LessOrEqual:1,Equal:2,MoreOrEqual:3,MoreThan:4". For instance, if LessThan is chosen then any node that gets a dot product value of less than the value of filtering_value will be filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDotProductToPositionVector3SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Checks if a specific position is in front of or behind a search space node. 5 | 6 | 7 | The [Vector3] dot product to position search criterion can be used to check if a specific position is in front of or behind a search space node. It calculates a direction vector using the [member dot_product_position] and the node global position. Then, it calculates a dot product using the direction vector and the search space node direction ([code]-global_transform.basis.z[/code] rotated by rotation). 8 | 9 | 10 | 11 | 12 | 13 | The global position to use in the dot product calculation. 14 | 15 | 16 | If filtering is in use, the result given by the dot product is compared to this value for filtering. 17 | 18 | 19 | If filtering is in use, this is the comparison that is done to decide on the filtering. The choices are: "LessThan:0,LessOrEqual:1,Equal:2,MoreOrEqual:3,MoreThan:4". For instance, if LessThan is chosen then any node that gets a dot product value of less than the value of filtering_value will be filtered out. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDotProductVector2SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based the angle the set [member dot_product_vector] has compared to the search space node direction. 5 | 6 | 7 | The [Vector2] dot product search criterion can be used to score and filter based the angle the set [member dot_product_vector] has compared to the search space node direction ([code]Vector2(1,0)[/code] rotated by rotation). 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIDotProductVector3SearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Scores and filters based the angle the set [member dot_product_vector] has compared to the search space node direction. 5 | 6 | 7 | The [Vector3] dot product search criterion can be used to score and filter based the angle the set [member dot_product_vector] has compared to the search space node direction ([code]-global_transform.basis.z[/code] rotated by rotation). 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIFloatRangeSensor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Accepts a minimum and maximum value that defines a value range. The input value given is scaled to 0..1 range within the given min and max values. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | The maximum value for the range. 13 | 14 | 15 | The minimum value for the range. 16 | 17 | 18 | Input value for the sensor. 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIIntRangeSensor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Accepts a minimum and maximum value that defines a value range. The input value given is scaled to 0..1 range within the given min and max values. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | The maximum value for the range. 13 | 14 | 15 | The minimum value for the range. 16 | 17 | 18 | Input value for the sensor. 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /doc_classes/UtilityAIMetadataSearchCriterion.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Filters nodes based on their metadata. 5 | 6 | 7 | The metadata search criterion can be used to filter nodes based on their metadata. Currently only metadata with type [String] is supported. Both the [param name] and [param value] of the metadata must match, otherwise the node will be filtered out. 8 | 9 | 10 | 11 | 12 | 13 | The name of the metadata field to find. 14 | 15 | 16 | The value of the named metadata field. 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc_classes/UtilityAINQSSearchCriteria.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Filter and score the nodes fetched using the search spaces. 5 | 6 | 7 | The search criteria nodes are used to filter and score the nodes fetched using the search spaces. There are general criterias that can be used with any Godot node and specific criteria for 2D and 3D related search spaces. 8 | Each criterion has an internal [code]apply_criterion()[/code] method that is applied to the node passed to it. This method updates the [member is_filtered] and score properties of the criterion and the results are visible in the Godot Engine editor inspector. 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Used in [code]apply_criterion()[/code]. If set to [code]true[/code], the will be filtered out. 17 | 18 | 19 | Used in [code]apply_criterion()[/code]. The score calculated by [code]apply_criterion()[/code]. Default value: [code]1.0[/code]. 20 | 21 | 22 | If [code]true[/code], the criterion will be used for filtering. 23 | 24 | 25 | If [code]true[/code], the criterion will be used for scoring. 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /doc_classes/UtilityAINodeChildrenSearchSpace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Returns the direct children of the given node as a search space. 5 | 6 | 7 | This node uses the children of a node to construct the search space. The direct children of the given node are returned as the search space. 8 | 9 | 10 | 11 | 12 | 13 | The parent node to use in the search. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc_classes/UtilityAINodeGroupSearchSpace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Constructs a search space from a [member group_name] and returns all matching nodes in the group. 5 | 6 | 7 | This node uses the node grouping property of the Godot Engine to construct the search space. All the nodes in the given group are returned as the search space. 8 | 9 | 10 | 11 | 12 | 13 | The group name to use in the search. 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc_classes/UtilityAISTNode.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | This is the workhorse of the State Tree. It acts as all the other levels of the state tree other than the tree root. If a [UtilityAISTNode] has no child nodes, it is considered a leaf node. If it has child nodes, it is considered like a selector in a behaviour tree: it will evaluate its child nodes to find a leaf node to activate. 7 | To make use of the [UtilityAISTNode], define the following methods for all the nodes: 8 | [gdscript] 9 | extends UtilityAISTNode 10 | 11 | func on_enter_condition(user_data: Variant, delta: float) -> bool: 12 | # Do your logic here to decide when this node should be activated. 13 | # Return true or false based on your logic. 14 | return true 15 | 16 | func on_enter_state(user_data: Variant, delta: float) -> void: 17 | # Initialize your state here. 18 | pass 19 | 20 | func on_exit_state(user_data: Variant, delta: float) -> void: 21 | # Clean up before exiting the state here. 22 | pass 23 | 24 | func on_tick(user_data: Variant, delta: float) -> void: 25 | # Do what ever the state needs to do here. 26 | pass 27 | [/gdscript] 28 | [b]Note:[/b] You can rename the [param user_data] parameter what ever you want. Most common ones would be blackboard if you are using a dictionary to share variables between your states, and actor if you just pass the root node of your AI entity scene. 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /doc_classes/UtilityAISTRoot.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The root node for a State Tree. 5 | 6 | 7 | This is the root node for a State Tree. To update the tree, you call the [method tick] method of its root node. This will tick all the child nodes. 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | The [method tick] method is used to update the State Tree state. You can provide any Godot variant type as a parameter (usually a node used as an actor or a dictionary used as a blackboard), along with a delta-time. User_data and delta are passed to the [code]on_enter_state()[/code], [code]on_exit_state()[/code], [code]on_tick()[/code] and [code]on_enter_condition()[/code] methods of the child nodes. 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | The time to complete a tick in usec. 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /doc_classes/UtilityAISensor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Provides input data to consideration nodes. 5 | 6 | 7 | This node type should be added as child nodes of the [UtilityAIAgent] node. It is used to give input data to consideration nodes. A sensor is used by one or more consideration nodes. A sensor group is a node that can be used to aggregate input from several sensors (or sensor groups) for a higher-level input to the consideration nodes. 8 | Why use sensors in the first place? 9 | Consider the situation where you have several behaviours that use the "IsPlayerClose" consideration and maybe different variations, such as "IsPlayerAboutMidDistanceFromMe" or what ever. With the sensor nodes you can calculate the distance once and set it to a sensor, and then all the various considerations can make use of the distance in a relatively easy way and the distance only needs to be calculated once. 10 | The specialized sensors also have the added benefit that their logic is done on C++ instead of gdscript. This gives them a performance boost compared to writing similar logic in gdscript. 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /doc_classes/UtilityAISensorGroup.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Aggregates input from several sensors (or sensor groups) for a higher-level input to the consideration nodes. 5 | 6 | 7 | This node type should be added as child nodes of the [UtilityAIAgent] node. It is used to give input data to consideration nodes. A sensor is used by one or more consideration nodes. A sensor group is a node that can be used to aggregate input from several sensors (or sensor groups) for a higher-level input to the consideration nodes. 8 | 9 | 10 | 11 | 12 | 13 | A choice of how the sensors and sensor groups that are childs of the node are aggregated. Can be one of the following: Sum:0,Min:1,Max:2,Mean:3,Multiply:4,FirstNonZero:5. 14 | 15 | 16 | This inverts the group sensor_value by calculating: [code]sensor_value = 1.0 - sensor_value[/code]. It is applied after all the child nodes have been evaluated. 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc_classes/UtilityAISensors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Base class for [UtilityAISensor] and [UtilityAISensorGroup]. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | A floating point value in the range of [code]0..1[/code]. 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/agent_behaviours/action.cpp: -------------------------------------------------------------------------------- 1 | #include "action.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace godot; 8 | 9 | // Method binds. 10 | 11 | void UtilityAIAction::_bind_methods() { 12 | ClassDB::bind_method(D_METHOD("set_action_id", "action_id"), &UtilityAIAction::set_action_id); 13 | ClassDB::bind_method(D_METHOD("get_action_id"), &UtilityAIAction::get_action_id); 14 | ADD_PROPERTY(PropertyInfo(Variant::INT, "action_id", PROPERTY_HINT_NONE), "set_action_id", "get_action_id"); 15 | 16 | // Signals. 17 | 18 | ADD_SIGNAL(MethodInfo("action_entered")); 19 | ADD_SIGNAL(MethodInfo("physics_frame_tick", PropertyInfo(Variant::FLOAT, "delta"))); 20 | ADD_SIGNAL(MethodInfo("idle_frame_tick", PropertyInfo(Variant::FLOAT, "delta"))); 21 | ADD_SIGNAL(MethodInfo("action_exited")); 22 | } 23 | 24 | // Constructor and destructor. 25 | 26 | UtilityAIAction::UtilityAIAction() { 27 | _action_id = 0; 28 | } 29 | 30 | UtilityAIAction::~UtilityAIAction() { 31 | } 32 | 33 | // Handling functions. 34 | 35 | bool UtilityAIAction::start_action() { 36 | set_is_finished(false); 37 | set_has_failed(false); 38 | emit_signal("action_entered"); 39 | return true; 40 | } 41 | 42 | bool UtilityAIAction::end_action() { 43 | emit_signal("action_exited"); 44 | set_is_finished(false); 45 | set_has_failed(false); 46 | return true; 47 | } 48 | 49 | Node *UtilityAIAction::step_actions() { 50 | if (get_is_finished()) { 51 | set_is_finished(false); 52 | return nullptr; 53 | } 54 | return this; 55 | } 56 | 57 | // Getters and Setters. 58 | 59 | void UtilityAIAction::set_action_id(int action_id) { 60 | _action_id = action_id; 61 | } 62 | 63 | int UtilityAIAction::get_action_id() const { 64 | return _action_id; 65 | } 66 | -------------------------------------------------------------------------------- /src/agent_behaviours/action.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIAction_H_INCLUDED 2 | #define UtilityAIAction_H_INCLUDED 3 | 4 | #include "actions.h" 5 | 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIAction : public UtilityAIActions { 11 | GDCLASS(UtilityAIAction, UtilityAIActions) 12 | 13 | private: 14 | int _action_id; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | 19 | public: 20 | UtilityAIAction(); 21 | ~UtilityAIAction(); 22 | 23 | // Getters and setters for attributes. 24 | 25 | void set_action_id(int action_id); 26 | int get_action_id() const; 27 | 28 | // Handling functions. 29 | 30 | virtual bool start_action() override; 31 | virtual bool end_action() override; 32 | virtual Node *step_actions() override; 33 | }; 34 | 35 | } //namespace godot 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/agent_behaviours/action_group.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIActionGroup_H_INCLUDED 2 | #define UtilityAIActionGroup_H_INCLUDED 3 | 4 | #include "actions.h" 5 | #include 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIActionGroup : public UtilityAIActions { 11 | GDCLASS(UtilityAIActionGroup, UtilityAIActions) 12 | 13 | private: 14 | int _action_execution_rule; 15 | int _error_handling_rule; 16 | int _current_action_index; 17 | bool _if_else_boolean_value; 18 | 19 | Ref _rnd; 20 | 21 | protected: 22 | static void _bind_methods(); 23 | 24 | public: 25 | UtilityAIActionGroup(); 26 | ~UtilityAIActionGroup(); 27 | 28 | // Getters and setters for attributes. 29 | 30 | void set_action_execution_rule(int action_execution_rule); 31 | int get_action_execution_rule() const; 32 | 33 | enum UtilityAIActionGroupExecutionRule { 34 | Sequence = 0, 35 | PickOneAtRandom = 1, 36 | IfElse = 2, 37 | CustomRule = 3, 38 | //IfPreviousActionFailedElse = 4, 39 | }; 40 | 41 | void set_error_handling_rule(int error_handling_rule); 42 | int get_error_handling_rule() const; 43 | 44 | enum UtilityAIActionGroupErrorHandlingRule { 45 | EndExecution = 0, 46 | ContinueExecution = 1, 47 | }; 48 | 49 | void set_current_action_index(int current_action_index); 50 | int get_current_action_index() const; 51 | 52 | void set_if_else_boolean_value(bool if_else_boolean_value); 53 | bool get_if_else_boolean_value() const; 54 | 55 | // Handling functions. 56 | 57 | virtual bool start_action() override; 58 | virtual bool end_action() override; 59 | virtual Node *step_actions() override; 60 | }; 61 | 62 | } //namespace godot 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/agent_behaviours/actions.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIActions_H_INCLUDED 2 | #define UtilityAIActions_H_INCLUDED 3 | 4 | #include "../utility_ai.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIActions : public UtilityAI { 10 | GDCLASS(UtilityAIActions, UtilityAI) 11 | 12 | private: 13 | bool _is_finished; 14 | bool _has_failed; 15 | //bool _has_previous_step_failed; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | #ifdef DEBUG_ENABLED 20 | uint64_t _last_evaluated_timestamp; 21 | uint64_t _last_visited_timestamp; 22 | #endif 23 | public: 24 | UtilityAIActions(); 25 | ~UtilityAIActions(); 26 | 27 | // Getters and setters for attributes. 28 | #ifdef DEBUG_ENABLED 29 | inline uint64_t get_last_visited_timestamp() const { return _last_visited_timestamp; }; 30 | inline uint64_t get_last_evaluated_timestamp() const { return _last_evaluated_timestamp; }; 31 | inline void set_last_visited_timestamp(uint64_t new_timestamp) { _last_visited_timestamp = new_timestamp; }; 32 | inline void set_last_evaluated_timestamp(uint64_t new_timestamp) { _last_evaluated_timestamp = new_timestamp; }; 33 | #endif 34 | 35 | void set_is_finished(bool is_finished); 36 | bool get_is_finished() const; 37 | 38 | void set_has_failed(bool has_failed); 39 | bool get_has_failed() const; 40 | 41 | //void set_has_previous_step_failed( bool has_previous_step_failed ); 42 | //bool get_has_previous_step_failed() const; 43 | 44 | // Handling functions. 45 | virtual Node *step_actions(); 46 | 47 | virtual bool start_action(); 48 | virtual bool end_action(); 49 | }; 50 | 51 | } //namespace godot 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/agent_behaviours/behaviour_group.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBEHAVIOURGROUP_H_INCLUDED 2 | #define UtilityAIBEHAVIOURGROUP_H_INCLUDED 3 | 4 | #include "behaviours.h" 5 | #include "considerations.h" 6 | #include "resources/considerations/consideration_resources.h" 7 | #include "utility_ai.h" 8 | #include 9 | 10 | namespace godot { 11 | 12 | class UtilityAIBehaviourGroup : public UtilityAIBehaviours { 13 | GDCLASS(UtilityAIBehaviourGroup, UtilityAIBehaviours) 14 | 15 | private: 16 | //float _score; 17 | float _activation_score; 18 | //TypedArray _considerations; 19 | 20 | //std::vector _child_considerations; 21 | //unsigned int _num_child_considerations; 22 | protected: 23 | static void _bind_methods(); 24 | #ifdef DEBUG_ENABLED 25 | uint64_t _last_evaluated_timestamp; 26 | uint64_t _last_visited_timestamp; 27 | #endif 28 | public: 29 | UtilityAIBehaviourGroup(); 30 | ~UtilityAIBehaviourGroup(); 31 | 32 | // Getters and setters for attributes. 33 | 34 | #ifdef DEBUG_ENABLED 35 | inline uint64_t get_last_visited_timestamp() const { return _last_visited_timestamp; }; 36 | inline uint64_t get_last_evaluated_timestamp() const { return _last_evaluated_timestamp; }; 37 | #endif 38 | 39 | void set_activation_score(float score); 40 | float get_activation_score() const override; 41 | 42 | //void set_score( float score ); 43 | //float get_score() const; 44 | 45 | void set_considerations(TypedArray considerations); 46 | TypedArray get_considerations() const; 47 | 48 | // Handling functions. 49 | 50 | float evaluate() override; 51 | bool is_behaviour_group() const override { return true; }; 52 | 53 | // Godot virtuals. 54 | //void _notification(int p_what); 55 | }; 56 | 57 | } //namespace godot 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/agent_behaviours/behaviours.cpp: -------------------------------------------------------------------------------- 1 | #include "behaviours.h" 2 | 3 | using namespace godot; 4 | 5 | void UtilityAIBehaviours::_bind_methods() { 6 | ClassDB::bind_method(D_METHOD("set_evaluation_method", "evaluation_method"), &UtilityAIBehaviours::set_evaluation_method); 7 | ClassDB::bind_method(D_METHOD("get_evaluation_method"), &UtilityAIBehaviours::get_evaluation_method); 8 | ADD_PROPERTY(PropertyInfo(Variant::INT, "evaluation_method", PROPERTY_HINT_ENUM, "Sum:0,Min:1,Max:2,Mean:3,Multiply:4,FirstNonZero:5"), "set_evaluation_method", "get_evaluation_method"); 9 | 10 | ClassDB::bind_method(D_METHOD("set_score", "score"), &UtilityAIBehaviours::set_score); 11 | ClassDB::bind_method(D_METHOD("get_score"), &UtilityAIBehaviours::get_score); 12 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "score", PROPERTY_HINT_RANGE, "-100.0,100.0"), "set_score", "get_score"); 13 | } 14 | 15 | // Godot virtuals. 16 | 17 | void UtilityAIBehaviours::_notification(int p_what) { 18 | if (p_what == NOTIFICATION_CHILD_ORDER_CHANGED) { 19 | _child_considerations.clear(); 20 | _child_behaviours.clear(); 21 | int num_children = get_child_count(); 22 | for (int i = 0; i < num_children; ++i) { 23 | if (UtilityAIConsiderations *cons = godot::Object::cast_to(get_child(i))) { 24 | _child_considerations.push_back(cons); 25 | } else if (UtilityAIBehaviours *beh = godot::Object::cast_to(get_child(i))) { 26 | _child_behaviours.push_back(beh); 27 | } 28 | } //endfor child nodes 29 | _num_child_considerations = (unsigned int)_child_considerations.size(); 30 | _num_child_behaviours = (unsigned int)_child_behaviours.size(); 31 | } 32 | } 33 | 34 | // Getters and setters. 35 | 36 | void UtilityAIBehaviours::set_evaluation_method(int evaluation_method) { 37 | _evaluation_method = evaluation_method; 38 | } 39 | 40 | int UtilityAIBehaviours::get_evaluation_method() const { 41 | return _evaluation_method; 42 | } 43 | -------------------------------------------------------------------------------- /src/agent_behaviours/consideration.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIConsideration_H_INCLUDED 2 | #define UtilityAIConsideration_H_INCLUDED 3 | 4 | #include "considerations.h" 5 | #include "sensors.h" 6 | #include 7 | #include 8 | 9 | namespace godot { 10 | 11 | class UtilityAIConsideration : public UtilityAIConsiderations { 12 | GDCLASS(UtilityAIConsideration, UtilityAIConsiderations) 13 | 14 | private: 15 | protected: 16 | static void _bind_methods(); 17 | 18 | UtilityAISensors *_input_sensor; 19 | Ref _activation_curve; 20 | float _activation_input_value; 21 | bool _has_custom_evaluation_method; 22 | bool _has_activation_input_changed; 23 | 24 | virtual void _evaluate_consideration(); 25 | 26 | public: 27 | UtilityAIConsideration(); 28 | ~UtilityAIConsideration(); 29 | 30 | // Getters and setters for attributes. 31 | 32 | void set_input_sensor(UtilityAISensors *input_sensor); 33 | virtual UtilityAISensors *get_input_sensor() const; 34 | 35 | void set_activation_curve(Ref activation_curve); 36 | Ref get_activation_curve() const; 37 | 38 | void set_activation_input_value(float activation_input_value); 39 | float get_activation_input_value() const; 40 | 41 | // Godot virtuals. 42 | virtual void _notification(int p_what); 43 | 44 | // Handling functions. 45 | 46 | virtual float evaluate() override; 47 | virtual float sample_activation_curve(float input_value) const; 48 | }; 49 | 50 | } //namespace godot 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/agent_behaviours/consideration_group.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIConsiderationGROUP_H_INCLUDED 2 | #define UtilityAIConsiderationGROUP_H_INCLUDED 3 | 4 | #include "considerations.h" 5 | 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIConsiderationGroup : public UtilityAIConsiderations { 11 | GDCLASS(UtilityAIConsiderationGroup, UtilityAIConsiderations) 12 | 13 | private: 14 | int _evaluation_method; 15 | bool _invert_score; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | 20 | public: 21 | UtilityAIConsiderationGroup(); 22 | ~UtilityAIConsiderationGroup(); 23 | 24 | // Getters and setters for attributes. 25 | 26 | void set_evaluation_method(int evaluation_method); 27 | int get_evaluation_method() const; 28 | 29 | enum UtilityAIConsiderationGroupEvaluationMethod { 30 | Sum = 0, 31 | Min = 1, 32 | Max = 2, 33 | Mean = 3, 34 | Multiply = 4, 35 | FirstNonZero = 5, 36 | //OneMinusScore=6 37 | }; 38 | 39 | void set_invert_score(bool invert_score); 40 | bool get_invert_score() const; 41 | 42 | // Handling functions. 43 | 44 | virtual float evaluate() override; //UtilityAIAgent* agent, float delta) override; 45 | }; 46 | 47 | } //namespace godot 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/agent_behaviours/considerations.cpp: -------------------------------------------------------------------------------- 1 | #include "considerations.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace godot; 8 | 9 | // Method binds. 10 | 11 | void UtilityAIConsiderations::_bind_methods() { 12 | ClassDB::bind_method(D_METHOD("set_has_vetoed", "has_vetoed"), &UtilityAIConsiderations::set_has_vetoed); 13 | ClassDB::bind_method(D_METHOD("get_has_vetoed"), &UtilityAIConsiderations::get_has_vetoed); 14 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "has_vetoed", PROPERTY_HINT_NONE), "set_has_vetoed", "get_has_vetoed"); 15 | 16 | ClassDB::bind_method(D_METHOD("set_score", "score"), &UtilityAIConsiderations::set_score); 17 | ClassDB::bind_method(D_METHOD("get_score"), &UtilityAIConsiderations::get_score); 18 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "score", PROPERTY_HINT_NONE), "set_score", "get_score"); 19 | } 20 | 21 | // Constructor and destructor. 22 | 23 | UtilityAIConsiderations::UtilityAIConsiderations() { 24 | _has_vetoed = false; 25 | _score = 0.0f; 26 | } 27 | 28 | UtilityAIConsiderations::~UtilityAIConsiderations() { 29 | } 30 | 31 | // Handling functions. 32 | 33 | // Getters and Setters. 34 | 35 | void UtilityAIConsiderations::set_has_vetoed(bool has_vetoed) { 36 | _has_vetoed = has_vetoed; 37 | } 38 | 39 | bool UtilityAIConsiderations::get_has_vetoed() const { 40 | return _has_vetoed; 41 | } 42 | 43 | void UtilityAIConsiderations::set_score(float score) { 44 | _score = score; 45 | } 46 | 47 | float UtilityAIConsiderations::get_score() const { 48 | return _score; 49 | } 50 | 51 | float UtilityAIConsiderations::evaluate() { 52 | return 0.0f; 53 | } 54 | -------------------------------------------------------------------------------- /src/agent_behaviours/considerations.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIConsiderations_H_INCLUDED 2 | #define UtilityAIConsiderations_H_INCLUDED 3 | 4 | #include "../utility_ai.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIConsiderations : public UtilityAI { 10 | GDCLASS(UtilityAIConsiderations, UtilityAI) 11 | 12 | private: 13 | protected: 14 | static void _bind_methods(); 15 | 16 | float _score; 17 | bool _has_vetoed; 18 | #ifdef DEBUG_ENABLED 19 | uint64_t _last_evaluated_timestamp; 20 | uint64_t _last_visited_timestamp; 21 | #endif 22 | public: 23 | UtilityAIConsiderations(); 24 | ~UtilityAIConsiderations(); 25 | 26 | // Getters and setters for attributes. 27 | 28 | #ifdef DEBUG_ENABLED 29 | inline uint64_t get_last_visited_timestamp() const { return _last_visited_timestamp; }; 30 | inline uint64_t get_last_evaluated_timestamp() const { return _last_evaluated_timestamp; }; 31 | #endif 32 | 33 | void set_has_vetoed(bool has_vetoed); 34 | bool get_has_vetoed() const; 35 | 36 | void set_score(float score); 37 | float get_score() const; 38 | 39 | // Handling functions. 40 | 41 | virtual float evaluate(); 42 | }; 43 | 44 | } //namespace godot 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/agent_behaviours/considerations/boolean.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBooleanConsideration_H_INCLUDED 2 | #define UtilityAIBooleanConsideration_H_INCLUDED 3 | 4 | #include "../consideration.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIBooleanConsideration : public UtilityAIConsideration { 9 | GDCLASS(UtilityAIBooleanConsideration, UtilityAIConsideration) 10 | 11 | private: 12 | float _true_score_value; 13 | float _false_score_value; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | virtual void _evaluate_consideration() override; 19 | 20 | public: 21 | UtilityAIBooleanConsideration(); 22 | ~UtilityAIBooleanConsideration(); 23 | 24 | // Getters and setters for attributes. 25 | 26 | void set_true_score_value(float true_score_value); 27 | float get_true_score_value() const; 28 | 29 | void set_false_score_value(float false_score_value); 30 | float get_false_score_value() const; 31 | 32 | // Godot virtuals. 33 | //void _ready(); 34 | //void _notification( int p_what ); 35 | 36 | // Handling functions. 37 | 38 | virtual float sample_activation_curve(float input_value) const override; 39 | }; 40 | 41 | } //namespace godot 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/agent_behaviours/considerations/custom_property.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAICustomPropertyConsideration_H_INCLUDED 2 | #define UtilityAICustomPropertyConsideration_H_INCLUDED 3 | 4 | #include "../considerations.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAICustomPropertyConsideration : public UtilityAIConsiderations { 10 | GDCLASS(UtilityAICustomPropertyConsideration, UtilityAIConsiderations) 11 | 12 | private: 13 | Node *_node_with_property; 14 | StringName _property_name; 15 | float _property_max_value; 16 | float _one_over_property_max_value; 17 | Variant _property_variant_value; 18 | Ref _activation_curve; 19 | 20 | protected: 21 | static void _bind_methods(); 22 | 23 | public: 24 | UtilityAICustomPropertyConsideration(); 25 | ~UtilityAICustomPropertyConsideration(); 26 | 27 | // Getters and setters for attributes. 28 | 29 | void set_activation_curve(Ref activation_curve); 30 | Ref get_activation_curve() const; 31 | 32 | void set_node_with_property(Node *node_with_property); 33 | Node *get_node_with_property() const; 34 | 35 | void set_property_max_value(float true_score_value); 36 | float get_property_max_value() const; 37 | 38 | void set_property_name(StringName property_name); 39 | StringName get_property_name() const; 40 | 41 | // Godot virtuals. 42 | void _ready() override; 43 | //void _notification( int p_what ); 44 | 45 | // Handling functions. 46 | void initialize_consideration(); 47 | virtual float evaluate() override; 48 | virtual float sample_activation_curve(float input_value) const; 49 | //virtual float sample_activation_curve( float input_value ) const; 50 | }; 51 | 52 | } //namespace godot 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensor.cpp: -------------------------------------------------------------------------------- 1 | #include "sensor.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace godot; 8 | 9 | // Method binds. 10 | 11 | void UtilityAISensor::_bind_methods() { 12 | } 13 | 14 | // Constructor and destructor. 15 | 16 | UtilityAISensor::UtilityAISensor() { 17 | } 18 | 19 | UtilityAISensor::~UtilityAISensor() { 20 | } 21 | 22 | // Handling functions. 23 | 24 | float UtilityAISensor::evaluate_sensor_value() { 25 | _has_sensor_value_changed = false; 26 | return get_sensor_value(); 27 | } 28 | 29 | // Getters and Setters. 30 | 31 | // Godot virtuals. 32 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensor.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAISensor_H_INCLUDED 2 | #define UtilityAISensor_H_INCLUDED 3 | 4 | #include "sensors.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAISensor : public UtilityAISensors { 10 | GDCLASS(UtilityAISensor, UtilityAISensors) 11 | 12 | private: 13 | protected: 14 | static void _bind_methods(); 15 | 16 | public: 17 | UtilityAISensor(); 18 | ~UtilityAISensor(); 19 | 20 | // Handling functions. 21 | 22 | virtual float evaluate_sensor_value() override; 23 | 24 | // Getters and setters for attributes. 25 | }; 26 | 27 | } //namespace godot 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensor_group.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAISensorGroup_H_INCLUDED 2 | #define UtilityAISensorGroup_H_INCLUDED 3 | 4 | #include "sensors.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAISensorGroup : public UtilityAISensors { 10 | GDCLASS(UtilityAISensorGroup, UtilityAISensors) 11 | 12 | private: 13 | int _evaluation_method; 14 | bool _invert_sensor_value; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | 19 | public: 20 | UtilityAISensorGroup(); 21 | ~UtilityAISensorGroup(); 22 | 23 | // Getters and setters for attributes. 24 | 25 | void set_evaluation_method(int evaluation_method); 26 | int get_evaluation_method() const; 27 | 28 | enum UtilityAISensorGroupEvaluationMethod { 29 | Sum = 0, 30 | Min = 1, 31 | Max = 2, 32 | Mean = 3, 33 | Multiply = 4, 34 | FirstNonZero = 5, 35 | }; 36 | 37 | void set_invert_sensor_value(bool invert_sensor_value); 38 | bool get_invert_sensor_value() const; 39 | 40 | // Handling functions. 41 | 42 | virtual float evaluate_sensor_value() override; 43 | }; 44 | 45 | } //namespace godot 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAISensors_H_INCLUDED 2 | #define UtilityAISensors_H_INCLUDED 3 | 4 | #include "../utility_ai.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAISensors : public UtilityAI { 10 | GDCLASS(UtilityAISensors, UtilityAI) 11 | 12 | private: 13 | float _sensor_value; 14 | //bool _use_absolute_value; // Place holder for when in Godot the Curve X-value can be adjusted to any range other than 0..1. 15 | 16 | protected: 17 | static void _bind_methods(); 18 | 19 | bool _has_sensor_value_changed; 20 | #ifdef DEBUG_ENABLED 21 | uint64_t _last_evaluated_timestamp; 22 | uint64_t _last_visited_timestamp; 23 | #endif 24 | public: 25 | UtilityAISensors(); 26 | ~UtilityAISensors(); 27 | 28 | // Godot virtuals. 29 | 30 | void _ready() override; 31 | //void _enter_tree() override; 32 | void _exit_tree() override; 33 | 34 | // Handling methods. 35 | 36 | virtual void initialize_sensor(); 37 | virtual void uninitialize_sensor() {} 38 | 39 | // Getters and setters for attributes. 40 | 41 | #ifdef DEBUG_ENABLED 42 | inline uint64_t get_last_visited_timestamp() const { return _last_visited_timestamp; }; 43 | inline uint64_t get_last_evaluated_timestamp() const { return _last_evaluated_timestamp; }; 44 | #endif 45 | 46 | bool get_has_sensor_value_changed() const { return _has_sensor_value_changed; }; 47 | 48 | void set_sensor_value(float sensor_value); 49 | float get_sensor_value() const; 50 | 51 | //void set_use_absolute_value( bool use_absolute_value ); 52 | //bool get_use_absolute_value() const; 53 | 54 | virtual float evaluate_sensor_value(); 55 | }; 56 | 57 | } //namespace godot 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/angle_vector2.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAIANGLEVECTOR2SENSOR_H_INCLUDED 2 | #define UTILITYAIANGLEVECTOR2SENSOR_H_INCLUDED 3 | 4 | #include "../sensor.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIAngleVector2Sensor : public UtilityAISensor { 9 | GDCLASS(UtilityAIAngleVector2Sensor, UtilityAISensor) 10 | 11 | private: 12 | Vector2 _from_vector; 13 | Vector2 _to_vector; 14 | float _angle_radian; 15 | float _angle_degrees; 16 | float _min_angle_radian; 17 | float _min_angle_degrees; 18 | float _max_angle_radian; 19 | float _max_angle_degrees; 20 | float _one_over_2_pi; 21 | //float _one_over_min_angle_radian; 22 | //float _one_over_max_angle_radian; 23 | protected: 24 | static void _bind_methods(); 25 | 26 | public: 27 | UtilityAIAngleVector2Sensor(); 28 | ~UtilityAIAngleVector2Sensor(); 29 | 30 | // Handling functions. 31 | 32 | virtual float evaluate_sensor_value() override; 33 | 34 | // Getters and setters for attributes. 35 | 36 | // Configuration values. 37 | 38 | void set_to_vector2(Vector2 to); 39 | Vector2 get_to_vector2() const; 40 | 41 | void set_from_vector2(Vector2 from); 42 | Vector2 get_from_vector2() const; 43 | 44 | void set_min_angle_radian(float min_angle_radian); 45 | float get_min_angle_radian() const; 46 | 47 | void set_min_angle_degrees(float min_angle_radian); 48 | float get_min_angle_degrees() const; 49 | 50 | void set_max_angle_radian(float max_angle_radian); 51 | float get_max_angle_radian() const; 52 | 53 | void set_max_angle_degrees(float max_angle_radian); 54 | float get_max_angle_degrees() const; 55 | 56 | // Debugging / current values. 57 | 58 | void set_angle_radian(float angle_radian); 59 | float get_angle_radian() const; 60 | 61 | void set_angle_degrees(float angle_degrees); 62 | float get_angle_degrees() const; 63 | }; 64 | 65 | } //namespace godot 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/angle_vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAIANGLEVECTOR3SENSOR_H_INCLUDED 2 | #define UTILITYAIANGLEVECTOR3SENSOR_H_INCLUDED 3 | 4 | #include "../sensor.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIAngleVector3Sensor : public UtilityAISensor { 9 | GDCLASS(UtilityAIAngleVector3Sensor, UtilityAISensor) 10 | 11 | private: 12 | Vector3 _from_vector; 13 | Vector3 _to_vector; 14 | float _angle_radian; 15 | float _angle_degrees; 16 | float _max_angle_radian; 17 | float _max_angle_degrees; 18 | float _one_over_max_angle_radian; 19 | 20 | protected: 21 | static void _bind_methods(); 22 | 23 | public: 24 | UtilityAIAngleVector3Sensor(); 25 | ~UtilityAIAngleVector3Sensor(); 26 | 27 | // Handling functions. 28 | 29 | virtual float evaluate_sensor_value() override; 30 | 31 | // Getters and setters for attributes. 32 | 33 | // Configuration values. 34 | 35 | void set_to_vector3(Vector3 to); 36 | Vector3 get_to_vector3() const; 37 | 38 | void set_from_vector3(Vector3 from); 39 | Vector3 get_from_vector3() const; 40 | 41 | void set_max_angle_radian(float max_angle_radian); 42 | float get_max_angle_radian() const; 43 | 44 | void set_max_angle_degrees(float max_angle_radian); 45 | float get_max_angle_degrees() const; 46 | 47 | // Debugging / current values. 48 | 49 | void set_angle_radian(float angle_radian); 50 | float get_angle_radian() const; 51 | 52 | void set_angle_degrees(float angle_degrees); 53 | float get_angle_degrees() const; 54 | }; 55 | 56 | } //namespace godot 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/boolean.cpp: -------------------------------------------------------------------------------- 1 | #include "boolean.h" 2 | 3 | #include 4 | 5 | using namespace godot; 6 | 7 | // Method binds. 8 | 9 | void UtilityAIBooleanSensor::_bind_methods() { 10 | ClassDB::bind_method(D_METHOD("set_boolean_value", "boolean_value"), &UtilityAIBooleanSensor::set_boolean_value); 11 | ClassDB::bind_method(D_METHOD("get_boolean_value"), &UtilityAIBooleanSensor::get_boolean_value); 12 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "boolean_value", PROPERTY_HINT_NONE), "set_boolean_value", "get_boolean_value"); 13 | } 14 | 15 | // Constructor and destructor. 16 | 17 | UtilityAIBooleanSensor::UtilityAIBooleanSensor() { 18 | _boolean_value = false; 19 | } 20 | 21 | UtilityAIBooleanSensor::~UtilityAIBooleanSensor() { 22 | } 23 | 24 | // Handling functions. 25 | 26 | float UtilityAIBooleanSensor::evaluate_sensor_value() { 27 | // Here the absolute and relative are the same, so no calculation needed. 28 | set_sensor_value((float)_boolean_value); 29 | return get_sensor_value(); 30 | } 31 | 32 | // Getters and Setters. 33 | 34 | void UtilityAIBooleanSensor::set_boolean_value(bool boolean_value) { 35 | _has_sensor_value_changed = (_boolean_value != boolean_value); 36 | _boolean_value = boolean_value; 37 | } 38 | 39 | bool UtilityAIBooleanSensor::get_boolean_value() const { 40 | return _boolean_value; 41 | } 42 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/boolean.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAIBOOLEANSENSOR_H_INCLUDED 2 | #define UTILITYAIBOOLEANSENSOR_H_INCLUDED 3 | 4 | #include "../sensor.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBooleanSensor : public UtilityAISensor { 10 | GDCLASS(UtilityAIBooleanSensor, UtilityAISensor) 11 | 12 | private: 13 | bool _boolean_value; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | public: 19 | UtilityAIBooleanSensor(); 20 | ~UtilityAIBooleanSensor(); 21 | 22 | // Handling functions. 23 | 24 | virtual float evaluate_sensor_value() override; 25 | 26 | // Getters and setters for attributes. 27 | 28 | void set_boolean_value(bool boolean_value); 29 | bool get_boolean_value() const; 30 | }; 31 | 32 | } //namespace godot 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/distance_vector2.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAIDISTANCEVECTOR2SENSOR_H_INCLUDED 2 | #define UTILITYAIDISTANCEVECTOR2SENSOR_H_INCLUDED 3 | 4 | #include "../sensor.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDistanceVector2Sensor : public UtilityAISensor { 9 | GDCLASS(UtilityAIDistanceVector2Sensor, UtilityAISensor) 10 | 11 | private: 12 | Vector2 _from_vector; 13 | Vector2 _to_vector; 14 | Vector2 _from_to_vector; 15 | Vector2 _direction_vector; 16 | float _distance_squared; 17 | float _distance; 18 | float _max_distance_squared; 19 | float _one_over_max_distance_squared; 20 | float _max_distance; 21 | 22 | bool _is_distance_calculated; 23 | bool _is_direction_vector_calculated; 24 | 25 | protected: 26 | static void _bind_methods(); 27 | 28 | public: 29 | UtilityAIDistanceVector2Sensor(); 30 | ~UtilityAIDistanceVector2Sensor(); 31 | 32 | // Handling functions. 33 | 34 | virtual float evaluate_sensor_value() override; 35 | 36 | // Getters and setters for attributes. 37 | 38 | // Configuration values. 39 | 40 | void set_to_Vector2(Vector2 to); 41 | Vector2 get_to_Vector2() const; 42 | 43 | void set_from_Vector2(Vector2 from); 44 | Vector2 get_from_Vector2() const; 45 | 46 | void set_max_distance(float max_distance); 47 | float get_max_distance() const; 48 | 49 | void set_is_distance_calculated(bool is_distance_calculated); 50 | bool get_is_distance_calculated() const; 51 | 52 | void set_is_direction_vector_calculated(bool is_direction_vector_calculated); 53 | bool get_is_direction_vector_calculated() const; 54 | 55 | // Debugging / current values. 56 | 57 | void set_from_to_vector2(Vector2 from_to); 58 | Vector2 get_from_to_vector2() const; 59 | 60 | void set_direction_vector2(Vector2 direction); 61 | Vector2 get_direction_vector2() const; 62 | 63 | void set_distance(float distance); 64 | float get_distance() const; 65 | 66 | void set_distance_squared(float distance_squared); 67 | float get_distance_squared() const; 68 | }; 69 | 70 | } //namespace godot 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/distance_vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAIDISTANCEVECTOR3SENSOR_H_INCLUDED 2 | #define UTILITYAIDISTANCEVECTOR3SENSOR_H_INCLUDED 3 | 4 | #include "../sensor.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDistanceVector3Sensor : public UtilityAISensor { 9 | GDCLASS(UtilityAIDistanceVector3Sensor, UtilityAISensor) 10 | 11 | private: 12 | Vector3 _from_vector; 13 | Vector3 _to_vector; 14 | Vector3 _from_to_vector; 15 | Vector3 _direction_vector; 16 | float _distance_squared; 17 | float _distance; 18 | float _max_distance_squared; 19 | float _one_over_max_distance_squared; 20 | float _max_distance; 21 | 22 | bool _is_distance_calculated; 23 | bool _is_direction_vector_calculated; 24 | 25 | protected: 26 | static void _bind_methods(); 27 | 28 | public: 29 | UtilityAIDistanceVector3Sensor(); 30 | ~UtilityAIDistanceVector3Sensor(); 31 | 32 | // Handling functions. 33 | 34 | virtual float evaluate_sensor_value() override; 35 | 36 | // Getters and setters for attributes. 37 | 38 | // Configuration values. 39 | 40 | void set_to_vector3(Vector3 to); 41 | Vector3 get_to_vector3() const; 42 | 43 | void set_from_vector3(Vector3 from); 44 | Vector3 get_from_vector3() const; 45 | 46 | void set_max_distance(float max_distance); 47 | float get_max_distance() const; 48 | 49 | void set_is_distance_calculated(bool is_distance_calculated); 50 | bool get_is_distance_calculated() const; 51 | 52 | void set_is_direction_vector_calculated(bool is_direction_vector_calculated); 53 | bool get_is_direction_vector_calculated() const; 54 | 55 | // Debugging / current values. 56 | 57 | void set_from_to_vector3(Vector3 from_to); 58 | Vector3 get_from_to_vector3() const; 59 | 60 | void set_direction_vector3(Vector3 direction); 61 | Vector3 get_direction_vector3() const; 62 | 63 | void set_distance(float distance); 64 | float get_distance() const; 65 | 66 | void set_distance_squared(float distance_squared); 67 | float get_distance_squared() const; 68 | }; 69 | 70 | } //namespace godot 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/float_range.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAIFLOATRANGESENSOR_H_INCLUDED 2 | #define UTILITYAIFLOATRANGESENSOR_H_INCLUDED 3 | 4 | #include "../sensor.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIFloatRangeSensor : public UtilityAISensor { 10 | GDCLASS(UtilityAIFloatRangeSensor, UtilityAISensor) 11 | 12 | private: 13 | float _range_min_value; 14 | float _range_max_value; 15 | float _range_length; 16 | float _one_over_range_length; 17 | float _range_value; 18 | 19 | protected: 20 | static void _bind_methods(); 21 | 22 | public: 23 | UtilityAIFloatRangeSensor(); 24 | ~UtilityAIFloatRangeSensor(); 25 | 26 | // Handling functions. 27 | 28 | virtual float evaluate_sensor_value() override; 29 | 30 | // Getters and setters for attributes. 31 | 32 | void set_range_min_value(float range_min_value); 33 | float get_range_min_value() const; 34 | 35 | void set_range_max_value(float range_max_value); 36 | float get_range_max_value() const; 37 | 38 | void set_range_value(float range_value); 39 | float get_range_value() const; 40 | }; 41 | 42 | } //namespace godot 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/agent_behaviours/sensors/int_range.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAIINTRANGESENSOR_H_INCLUDED 2 | #define UTILITYAIINTRANGESENSOR_H_INCLUDED 3 | 4 | #include "../sensor.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIIntRangeSensor : public UtilityAISensor { 10 | GDCLASS(UtilityAIIntRangeSensor, UtilityAISensor) 11 | 12 | private: 13 | int _range_min_value; 14 | int _range_max_value; 15 | int _range_length; 16 | float _one_over_range_length; 17 | int _range_value; 18 | 19 | protected: 20 | static void _bind_methods(); 21 | 22 | public: 23 | UtilityAIIntRangeSensor(); 24 | ~UtilityAIIntRangeSensor(); 25 | 26 | // Handling functions. 27 | 28 | virtual float evaluate_sensor_value() override; 29 | 30 | // Getters and setters for attributes. 31 | 32 | void set_range_min_value(int range_min_value); 33 | int get_range_min_value() const; 34 | 35 | void set_range_max_value(int range_max_value); 36 | int get_range_max_value() const; 37 | 38 | void set_range_value(int range_value); 39 | int get_range_value() const; 40 | 41 | //void set_range_length( int range_length ); 42 | //int get_range_length() const; 43 | }; 44 | 45 | } //namespace godot 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/behaviour_tree/composite_nodes.cpp: -------------------------------------------------------------------------------- 1 | #include "composite_nodes.h" 2 | 3 | using namespace godot; 4 | 5 | UtilityAIBTCompositeNodes::UtilityAIBTCompositeNodes() { 6 | } 7 | 8 | UtilityAIBTCompositeNodes::~UtilityAIBTCompositeNodes() { 9 | } 10 | 11 | void UtilityAIBTCompositeNodes::_bind_methods() { 12 | } 13 | -------------------------------------------------------------------------------- /src/behaviour_tree/composite_nodes.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTCompositeNodes_H_INCLUDED 2 | #define UtilityAIBTCompositeNodes_H_INCLUDED 3 | 4 | #include "nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTCompositeNodes : public UtilityAIBehaviourTreeNodes { 10 | GDCLASS(UtilityAIBTCompositeNodes, UtilityAIBehaviourTreeNodes) 11 | 12 | private: 13 | protected: 14 | static void _bind_methods(); 15 | 16 | public: 17 | UtilityAIBTCompositeNodes(); 18 | ~UtilityAIBTCompositeNodes(); 19 | }; 20 | 21 | } //namespace godot 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/behaviour_tree/cooldown_msec.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTCooldownMsec_H_INCLUDED 2 | #define UtilityAIBTCooldownMsec_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTCooldownMsec : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTCooldownMsec, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | uint64_t _cooldown_msec; 14 | uint64_t _cooldown_start_timestamp; 15 | 16 | int _cooldown_return_value; 17 | bool _is_in_cooldown; 18 | 19 | protected: 20 | static void _bind_methods(); 21 | 22 | public: 23 | UtilityAIBTCooldownMsec(); 24 | ~UtilityAIBTCooldownMsec(); 25 | 26 | // Getters and setters for attributes. 27 | 28 | void set_cooldown_msec(int cooldown_msec); 29 | int get_cooldown_msec() const; 30 | 31 | void set_cooldown_start_timestamp(int cooldown_msec); 32 | int get_cooldown_start_timestamp() const; 33 | 34 | void set_cooldown_return_value(int cooldown_return_value); 35 | int get_cooldown_return_value() const; 36 | 37 | // Handling functions. 38 | 39 | virtual int tick(Variant user_data, float delta) override; 40 | }; 41 | 42 | } //namespace godot 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/behaviour_tree/cooldown_ticks.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTCooldownTicks_H_INCLUDED 2 | #define UtilityAIBTCooldownTicks_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTCooldownTicks : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTCooldownTicks, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | int _cooldown_ticks; 14 | int _current_cooldown_ticks; 15 | 16 | int _cooldown_return_value; 17 | 18 | protected: 19 | static void _bind_methods(); 20 | 21 | public: 22 | UtilityAIBTCooldownTicks(); 23 | ~UtilityAIBTCooldownTicks(); 24 | 25 | // Getters and setters for attributes. 26 | 27 | void set_cooldown_ticks(int cooldown_ticks); 28 | int get_cooldown_ticks() const; 29 | 30 | void set_current_cooldown_ticks(int cooldown_ticks); 31 | int get_current_cooldown_ticks() const; 32 | 33 | void set_cooldown_return_value(int cooldown_return_value); 34 | int get_cooldown_return_value() const; 35 | 36 | // Handling functions. 37 | 38 | virtual int tick(Variant user_data, float delta) override; 39 | }; 40 | 41 | } //namespace godot 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/behaviour_tree/cooldown_usec.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTCooldownUsec_H_INCLUDED 2 | #define UtilityAIBTCooldownUsec_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTCooldownUsec : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTCooldownUsec, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | uint64_t _cooldown_usec; 14 | uint64_t _cooldown_start_timestamp; 15 | 16 | int _cooldown_return_value; 17 | bool _is_in_cooldown; 18 | 19 | protected: 20 | static void _bind_methods(); 21 | 22 | public: 23 | UtilityAIBTCooldownUsec(); 24 | ~UtilityAIBTCooldownUsec(); 25 | 26 | // Getters and setters for attributes. 27 | 28 | void set_cooldown_usec(int cooldown_usec); 29 | int get_cooldown_usec() const; 30 | 31 | void set_cooldown_start_timestamp(int cooldown_Usec); 32 | int get_cooldown_start_timestamp() const; 33 | 34 | void set_cooldown_return_value(int cooldown_return_value); 35 | int get_cooldown_return_value() const; 36 | 37 | // Handling functions. 38 | 39 | virtual int tick(Variant user_data, float delta) override; 40 | }; 41 | 42 | } //namespace godot 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/behaviour_tree/decorator_nodes.cpp: -------------------------------------------------------------------------------- 1 | #include "decorator_nodes.h" 2 | 3 | using namespace godot; 4 | 5 | UtilityAIBTDecoratorNodes::UtilityAIBTDecoratorNodes() { 6 | } 7 | 8 | UtilityAIBTDecoratorNodes::~UtilityAIBTDecoratorNodes() { 9 | } 10 | 11 | void UtilityAIBTDecoratorNodes::_bind_methods() { 12 | } 13 | -------------------------------------------------------------------------------- /src/behaviour_tree/decorator_nodes.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTDecoratorNodes_H_INCLUDED 2 | #define UtilityAIBTDecoratorNodes_H_INCLUDED 3 | 4 | #include "nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTDecoratorNodes : public UtilityAIBehaviourTreeNodes { 10 | GDCLASS(UtilityAIBTDecoratorNodes, UtilityAIBehaviourTreeNodes) 11 | 12 | private: 13 | protected: 14 | static void _bind_methods(); 15 | 16 | public: 17 | UtilityAIBTDecoratorNodes(); 18 | ~UtilityAIBTDecoratorNodes(); 19 | }; 20 | 21 | } //namespace godot 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/behaviour_tree/definitions.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITYAI_BTDEFINITIONS_H_INCLUDED 2 | #define UTILITYAI_BTDEFINITIONS_H_INCLUDED 3 | 4 | #define BT_RUNNING 0 5 | #define BT_SUCCESS 1 6 | #define BT_FAILURE -1 7 | #define BT_SKIP -2 8 | 9 | #define BT_INTERNAL_STATUS_UNTICKED 0 10 | #define BT_INTERNAL_STATUS_TICKED 1 11 | #define BT_INTERNAL_STATUS_COMPLETED 2 12 | 13 | #endif -------------------------------------------------------------------------------- /src/behaviour_tree/fixed_result.cpp: -------------------------------------------------------------------------------- 1 | #include "fixed_result.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace godot; 7 | 8 | // Method binds. 9 | 10 | void UtilityAIBTFixedResult::_bind_methods() { 11 | ClassDB::bind_method(D_METHOD("set_fixed_result", "fixed_result"), &UtilityAIBTFixedResult::set_fixed_result); 12 | ClassDB::bind_method(D_METHOD("get_fixed_result"), &UtilityAIBTFixedResult::get_fixed_result); 13 | ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_result", PROPERTY_HINT_ENUM, "Running:0,Success:1,Failure:-1"), "set_fixed_result", "get_fixed_result"); 14 | 15 | //ClassDB::bind_method(D_METHOD("_tick", "user_data", "delta"), &UtilityAIBTFixedResult::tick); 16 | } 17 | 18 | // Constructor and destructor. 19 | 20 | UtilityAIBTFixedResult::UtilityAIBTFixedResult() { 21 | _fixed_result = BT_SUCCESS; 22 | } 23 | 24 | UtilityAIBTFixedResult::~UtilityAIBTFixedResult() { 25 | } 26 | 27 | // Getters and Setters. 28 | 29 | void UtilityAIBTFixedResult::set_fixed_result(int fixed_result) { 30 | _fixed_result = fixed_result; 31 | } 32 | 33 | int UtilityAIBTFixedResult::get_fixed_result() const { 34 | return _fixed_result; 35 | } 36 | 37 | // Handling methods. 38 | 39 | int UtilityAIBTFixedResult::tick(Variant user_data, float delta) { 40 | set_internal_status(BT_INTERNAL_STATUS_TICKED); 41 | //if( _is_first_tick ) { 42 | // _is_first_tick = false; 43 | // emit_signal("btnode_entered", user_data, delta); 44 | //} 45 | 46 | set_tick_result(_fixed_result); 47 | for (int i = 0; i < get_child_count(); ++i) { 48 | Node *node = get_child(i); 49 | if (UtilityAIBehaviourTreeNodes *btnode = godot::Object::cast_to(node)) { 50 | if (!btnode->get_is_active()) { 51 | continue; 52 | } 53 | btnode->tick(user_data, delta); 54 | //emit_signal("btnode_ticked", user_data, delta); 55 | break; 56 | } 57 | } 58 | set_internal_status(BT_INTERNAL_STATUS_COMPLETED); 59 | //emit_signal("btnode_exited", user_data, delta); 60 | return _fixed_result; 61 | } 62 | -------------------------------------------------------------------------------- /src/behaviour_tree/fixed_result.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTFixedResult_H_INCLUDED 2 | #define UtilityAIBTFixedResult_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTFixedResult : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTFixedResult, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | int _fixed_result; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | public: 19 | UtilityAIBTFixedResult(); 20 | ~UtilityAIBTFixedResult(); 21 | 22 | // Getters and setters for attributes. 23 | 24 | void set_fixed_result(int fixed_result); 25 | int get_fixed_result() const; 26 | 27 | // Handling functions. 28 | 29 | virtual int tick(Variant user_data, float delta) override; 30 | }; 31 | 32 | } //namespace godot 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/behaviour_tree/inverter.cpp: -------------------------------------------------------------------------------- 1 | #include "inverter.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace godot; 7 | 8 | // Method binds. 9 | 10 | void UtilityAIBTInverter::_bind_methods() { 11 | //ClassDB::bind_method(D_METHOD("_tick", "user_data", "delta"), &UtilityAIBTInverter::tick); 12 | } 13 | 14 | // Constructor and destructor. 15 | 16 | UtilityAIBTInverter::UtilityAIBTInverter() { 17 | } 18 | 19 | UtilityAIBTInverter::~UtilityAIBTInverter() { 20 | } 21 | 22 | // Getters and Setters. 23 | 24 | // Handling methods. 25 | 26 | int UtilityAIBTInverter::tick(Variant user_data, float delta) { 27 | set_internal_status(BT_INTERNAL_STATUS_TICKED); 28 | //if( _is_first_tick ) { 29 | // _is_first_tick = false; 30 | // emit_signal("btnode_entered", user_data, delta); 31 | //} 32 | 33 | for (int i = 0; i < get_child_count(); ++i) { 34 | Node *node = get_child(i); 35 | if (UtilityAIBehaviourTreeNodes *btnode = godot::Object::cast_to(node)) { 36 | if (!btnode->get_is_active()) { 37 | continue; 38 | } 39 | int result = -btnode->tick(user_data, delta); 40 | set_tick_result(result); 41 | //emit_signal("btnode_ticked", user_data, delta); 42 | if (result != BT_RUNNING) { 43 | set_internal_status(BT_INTERNAL_STATUS_COMPLETED); 44 | //emit_signal("btnode_exited", user_data, delta); 45 | } 46 | return result; 47 | } 48 | } 49 | set_internal_status(BT_INTERNAL_STATUS_COMPLETED); 50 | set_tick_result(BT_FAILURE); 51 | //emit_signal("btnode_exited", user_data, delta); 52 | return BT_FAILURE; 53 | } 54 | -------------------------------------------------------------------------------- /src/behaviour_tree/inverter.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTInverter_H_INCLUDED 2 | #define UtilityAIBTInverter_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTInverter : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTInverter, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | //int _tick_result; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | public: 19 | UtilityAIBTInverter(); 20 | ~UtilityAIBTInverter(); 21 | 22 | // Getters and setters for attributes. 23 | 24 | //void set_tick_result( int tick_result ); 25 | //int get_tick_result() const; 26 | 27 | // Handling functions. 28 | 29 | virtual int tick(Variant user_data, float delta) override; 30 | }; 31 | 32 | } //namespace godot 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/behaviour_tree/leaf.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTLeaf_H_INCLUDED 2 | #define UtilityAIBTLeaf_H_INCLUDED 3 | 4 | #include "task_nodes.h" 5 | #include 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIBTLeaf : public UtilityAIBTTaskNodes { 11 | GDCLASS(UtilityAIBTLeaf, UtilityAIBTTaskNodes) 12 | 13 | private: 14 | //Callable _tick_method; 15 | //int _tick_result; 16 | bool _has_on_tick_method; 17 | bool _has_tick_method; 18 | 19 | protected: 20 | static void _bind_methods(); 21 | 22 | public: 23 | UtilityAIBTLeaf(); 24 | ~UtilityAIBTLeaf(); 25 | 26 | // Getters and setters for attributes. 27 | 28 | //void set_tick_result( int tick_result ); 29 | //int get_tick_result() const; 30 | 31 | // Handling functions. 32 | 33 | virtual int tick(Variant user_data, float delta) override; 34 | 35 | // Godot virtuals. 36 | 37 | void _notification(int p_what) override; 38 | }; 39 | 40 | } //namespace godot 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/behaviour_tree/limiter.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTLimiter_H_INCLUDED 2 | #define UtilityAIBTLimiter_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTLimiter : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTLimiter, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | int _max_repeat_times; 14 | int _current_repeat_times; 15 | int _tick_result; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | 20 | public: 21 | UtilityAIBTLimiter(); 22 | ~UtilityAIBTLimiter(); 23 | 24 | // Getters and setters for attributes. 25 | 26 | int get_max_repeat_times() const; 27 | void set_max_repeat_times(int repeat_times); 28 | //int get_tick_result() const; 29 | //void set_tick_result( int tick_result ); 30 | 31 | // Handling functions. 32 | virtual void reset_bt_node() override; 33 | 34 | virtual int tick(Variant user_data, float delta) override; 35 | }; 36 | 37 | } //namespace godot 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/behaviour_tree/node_reference.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTNodeReference_H_INCLUDED 2 | #define UtilityAIBTNodeReference_H_INCLUDED 3 | 4 | #include "task_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTNodeReference : public UtilityAIBTTaskNodes { 10 | GDCLASS(UtilityAIBTNodeReference, UtilityAIBTTaskNodes) 11 | 12 | private: 13 | //int _tick_result; 14 | UtilityAIBehaviourTreeNodes *_node_reference; 15 | ObjectID _cache; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | 20 | void _update_cache(); 21 | 22 | public: 23 | UtilityAIBTNodeReference(); 24 | ~UtilityAIBTNodeReference(); 25 | 26 | // Getters and setters for attributes. 27 | 28 | void set_node_reference(UtilityAIBehaviourTreeNodes *node_reference); 29 | UtilityAIBehaviourTreeNodes *get_node_reference() const; 30 | //void set_tick_result( int tick_result ); 31 | //int get_tick_result() const; 32 | 33 | // Handling functions. 34 | virtual void reset() override; 35 | virtual int tick(Variant user_data, float delta) override; 36 | }; 37 | 38 | } //namespace godot 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/behaviour_tree/parallel.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTParallel_H_INCLUDED 2 | #define UtilityAIBTParallel_H_INCLUDED 3 | 4 | #include "composite_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTParallel : public UtilityAIBTCompositeNodes { 10 | GDCLASS(UtilityAIBTParallel, UtilityAIBTCompositeNodes) 11 | 12 | private: 13 | //bool _is_reactive; 14 | int _current_child_index; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | 19 | public: 20 | UtilityAIBTParallel(); 21 | ~UtilityAIBTParallel(); 22 | 23 | // Getters and setters for attributes. 24 | //void set_is_reactive( bool is_reactive ); 25 | //bool get_is_reactive() const; 26 | 27 | // Handling functions. 28 | 29 | virtual int tick(Variant user_data, float delta) override; 30 | }; 31 | 32 | } //namespace godot 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/behaviour_tree/pass_by.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTPassBy_H_INCLUDED 2 | #define UtilityAIBTPassBy_H_INCLUDED 3 | 4 | #include "task_nodes.h" 5 | #include 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIBTPassBy : public UtilityAIBTTaskNodes { 11 | GDCLASS(UtilityAIBTPassBy, UtilityAIBTTaskNodes) 12 | 13 | private: 14 | //int _tick_result; 15 | bool _has_on_tick_method; 16 | bool _has_tick_method; 17 | 18 | protected: 19 | static void _bind_methods(); 20 | 21 | public: 22 | UtilityAIBTPassBy(); 23 | ~UtilityAIBTPassBy(); 24 | 25 | // Getters and setters for attributes. 26 | 27 | //void set_tick_result( int tick_result ); 28 | //int get_tick_result() const; 29 | 30 | // Handling functions. 31 | 32 | virtual int tick(Variant user_data, float delta) override; 33 | 34 | // Godot virtuals. 35 | void _notification(int p_what) override; 36 | }; 37 | 38 | } //namespace godot 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/behaviour_tree/pass_through.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTPassThrough_H_INCLUDED 2 | #define UtilityAIBTPassThrough_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIBTPassThrough : public UtilityAIBTDecoratorNodes { 11 | GDCLASS(UtilityAIBTPassThrough, UtilityAIBTDecoratorNodes) 12 | 13 | private: 14 | int _tick_result; 15 | bool _has_on_tick_method; 16 | bool _has_tick_method; 17 | 18 | protected: 19 | static void _bind_methods(); 20 | 21 | public: 22 | UtilityAIBTPassThrough(); 23 | ~UtilityAIBTPassThrough(); 24 | 25 | // Getters and setters for attributes. 26 | 27 | void set_tick_result(int tick_result); 28 | int get_tick_result() const; 29 | 30 | // Handling functions. 31 | 32 | virtual int tick(Variant user_data, float delta) override; 33 | 34 | // Godot virtuals. 35 | void _notification(int p_what) override; 36 | }; 37 | 38 | } //namespace godot 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/behaviour_tree/random_selector.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTRandomSelector_H_INCLUDED 2 | #define UtilityAIBTRandomSelector_H_INCLUDED 3 | 4 | #include "composite_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTRandomSelector : public UtilityAIBTCompositeNodes { 10 | GDCLASS(UtilityAIBTRandomSelector, UtilityAIBTCompositeNodes) 11 | 12 | private: 13 | TypedArray _child_node_order; 14 | int _current_child_index; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | 19 | public: 20 | UtilityAIBTRandomSelector(); 21 | ~UtilityAIBTRandomSelector(); 22 | 23 | // Getters and setters for attributes. 24 | 25 | // Handling functions. 26 | 27 | virtual void reset_bt_node() override; 28 | 29 | virtual int tick(Variant user_data, float delta) override; 30 | }; 31 | 32 | } //namespace godot 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/behaviour_tree/random_sequence.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTRandomSequence_H_INCLUDED 2 | #define UtilityAIBTRandomSequence_H_INCLUDED 3 | 4 | #include "composite_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTRandomSequence : public UtilityAIBTCompositeNodes { 10 | GDCLASS(UtilityAIBTRandomSequence, UtilityAIBTCompositeNodes) 11 | 12 | private: 13 | //bool _is_reactive; 14 | int _current_child_index; 15 | TypedArray _child_node_order; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | 20 | public: 21 | UtilityAIBTRandomSequence(); 22 | ~UtilityAIBTRandomSequence(); 23 | 24 | // Getters and setters for attributes. 25 | //void set_is_reactive( bool is_reactive ); 26 | //bool get_is_reactive() const; 27 | 28 | // Handling functions. 29 | 30 | virtual void reset_bt_node() override; 31 | 32 | virtual int tick(Variant user_data, float delta) override; 33 | }; 34 | 35 | } //namespace godot 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/behaviour_tree/repeat_until.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTRepeatUntil_H_INCLUDED 2 | #define UtilityAIBTRepeatUntil_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTRepeatUntil : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTRepeatUntil, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | int _max_repeat_times; 14 | int _current_max_repeat_times; 15 | int _expected_tick_result; 16 | bool _is_expected_tick_result_reached; 17 | 18 | protected: 19 | static void _bind_methods(); 20 | 21 | public: 22 | UtilityAIBTRepeatUntil(); 23 | ~UtilityAIBTRepeatUntil(); 24 | 25 | // Getters and setters for attributes. 26 | 27 | int get_max_repeat_times() const; 28 | void set_max_repeat_times(int max_repeat_times); 29 | int get_current_max_repeat_times() const; 30 | void set_current_max_repeat_times(int current_max_repeat_times); 31 | int get_expected_tick_result() const; 32 | void set_expected_tick_result(int expected_tick_result); 33 | 34 | // Handling functions. 35 | 36 | virtual void reset_bt_node() override; 37 | 38 | virtual int tick(Variant user_data, float delta) override; 39 | }; 40 | 41 | } //namespace godot 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/behaviour_tree/repeater.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTRepeater_H_INCLUDED 2 | #define UtilityAIBTRepeater_H_INCLUDED 3 | 4 | #include "decorator_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTRepeater : public UtilityAIBTDecoratorNodes { 10 | GDCLASS(UtilityAIBTRepeater, UtilityAIBTDecoratorNodes) 11 | 12 | private: 13 | int _repeat_times; 14 | int _current_repeat_times; 15 | int _tick_result; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | 20 | public: 21 | UtilityAIBTRepeater(); 22 | ~UtilityAIBTRepeater(); 23 | 24 | // Getters and setters for attributes. 25 | 26 | int get_repeat_times() const; 27 | void set_repeat_times(int repeat_times); 28 | 29 | int get_current_repeat_times() const; 30 | void set_current_repeat_times(int repeat_times); 31 | //int get_tick_result() const; 32 | //void set_tick_result( int tick_result ); 33 | 34 | // Handling functions. 35 | virtual void reset_bt_node() override; 36 | virtual int tick(Variant user_data, float delta) override; 37 | }; 38 | 39 | } //namespace godot 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/behaviour_tree/root.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTRoot_H_INCLUDED 2 | #define UtilityAIBTRoot_H_INCLUDED 3 | 4 | #include "../agent_behaviours/sensors.h" 5 | #include "nodes.h" 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIBTRoot : public UtilityAIBehaviourTreeNodes { 11 | GDCLASS(UtilityAIBTRoot, UtilityAIBehaviourTreeNodes) 12 | 13 | private: 14 | #ifdef DEBUG_ENABLED 15 | uint64_t _total_tick_usec; 16 | #endif 17 | protected: 18 | static void _bind_methods(); 19 | 20 | std::vector _child_sensors; 21 | unsigned int _num_child_sensors; 22 | 23 | public: 24 | UtilityAIBTRoot(); 25 | ~UtilityAIBTRoot(); 26 | 27 | // Getters and setters for attributes. 28 | 29 | #ifdef DEBUG_ENABLED 30 | uint64_t get_total_tick_usec() const; 31 | void set_total_tick_usec(uint64_t total_tick_usec); 32 | #endif 33 | 34 | // Handling functions. 35 | 36 | virtual int tick(Variant user_data, float delta) override; 37 | 38 | // Godot virtuals. 39 | void _ready() override; 40 | }; 41 | 42 | } //namespace godot 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/behaviour_tree/run_nqs_query.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTRunNQSQuery_H_INCLUDED 2 | #define UtilityAIBTRunNQSQuery_H_INCLUDED 3 | 4 | #include "../node_query_system/node_query_system.h" 5 | #include "../node_query_system/search_spaces/nqs.h" 6 | #include "task_nodes.h" 7 | #include 8 | 9 | #define QS_IDLE 0 10 | #define QS_RUNNING 1 11 | #define QS_COMPLETED 2 12 | 13 | namespace godot { 14 | 15 | class UtilityAIBTRunNQSQuery : public UtilityAIBTTaskNodes { 16 | GDCLASS(UtilityAIBTRunNQSQuery, UtilityAIBTTaskNodes) 17 | 18 | private: 19 | //ObjectID _nqs_search_space_cache; 20 | UtilityAINQSSearchSpaces *_nqs_search_space; 21 | UtilityAINodeQuerySystem *_nqs; 22 | 23 | int _time_budget_usec; 24 | int _top_n_to_find; 25 | bool _is_high_priority; 26 | 27 | int _query_state; 28 | 29 | protected: 30 | static void _bind_methods(); 31 | 32 | public: 33 | UtilityAIBTRunNQSQuery(); 34 | ~UtilityAIBTRunNQSQuery(); 35 | 36 | // Getters and setters for attributes. 37 | 38 | void set_nqs_search_space(UtilityAINQSSearchSpaces *nqs_search_space); 39 | UtilityAINQSSearchSpaces *get_nqs_search_space() const; 40 | 41 | void set_time_budget_usec(int time_budget_usec); 42 | int get_time_budget_usec() const; 43 | 44 | void set_top_n_to_find(int top_n_to_find); 45 | int get_top_n_to_find() const; 46 | 47 | void set_is_high_priority(bool is_high_priority); 48 | bool get_is_high_priority() const; 49 | 50 | // Handling functions. 51 | virtual void reset_bt_node() override; 52 | virtual int tick(Variant user_data, float delta) override; 53 | 54 | // Godot virtuals. 55 | 56 | void _ready() override; 57 | void _physics_process(double delta) override; 58 | }; 59 | 60 | } //namespace godot 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/behaviour_tree/score_based_picker.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTScoreBasedPicker_H_INCLUDED 2 | #define UtilityAIBTScoreBasedPicker_H_INCLUDED 3 | 4 | #include "composite_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTScoreBasedPicker : public UtilityAIBTCompositeNodes { 10 | GDCLASS(UtilityAIBTScoreBasedPicker, UtilityAIBTCompositeNodes) 11 | 12 | private: 13 | //bool _is_reactive; 14 | int _current_child_index; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | 19 | public: 20 | UtilityAIBTScoreBasedPicker(); 21 | ~UtilityAIBTScoreBasedPicker(); 22 | 23 | // Getters and setters for attributes. 24 | //void set_is_reactive( bool is_reactive ); 25 | //bool get_is_reactive() const; 26 | 27 | // Handling functions. 28 | 29 | virtual void reset_bt_node() override; 30 | 31 | virtual int tick(Variant user_data, float delta) override; 32 | }; 33 | 34 | } //namespace godot 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/behaviour_tree/selector.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTSelector_H_INCLUDED 2 | #define UtilityAIBTSelector_H_INCLUDED 3 | 4 | #include "composite_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTSelector : public UtilityAIBTCompositeNodes { 10 | GDCLASS(UtilityAIBTSelector, UtilityAIBTCompositeNodes) 11 | 12 | private: 13 | int _current_child_index; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | public: 19 | UtilityAIBTSelector(); 20 | ~UtilityAIBTSelector(); 21 | 22 | // Handling functions. 23 | virtual void reset_bt_node() override; 24 | 25 | virtual int tick(Variant user_data, float delta) override; 26 | }; 27 | 28 | } //namespace godot 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/behaviour_tree/sequence.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTSequence_H_INCLUDED 2 | #define UtilityAIBTSequence_H_INCLUDED 3 | 4 | #include "composite_nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTSequence : public UtilityAIBTCompositeNodes { 10 | GDCLASS(UtilityAIBTSequence, UtilityAIBTCompositeNodes) 11 | 12 | private: 13 | int _current_child_index; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | public: 19 | UtilityAIBTSequence(); 20 | ~UtilityAIBTSequence(); 21 | 22 | // Handling functions. 23 | 24 | virtual void reset_bt_node() override; 25 | 26 | virtual int tick(Variant user_data, float delta) override; 27 | }; 28 | 29 | } //namespace godot 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/behaviour_tree/task_nodes.cpp: -------------------------------------------------------------------------------- 1 | #include "task_nodes.h" 2 | 3 | using namespace godot; 4 | 5 | UtilityAIBTTaskNodes::UtilityAIBTTaskNodes() { 6 | } 7 | 8 | UtilityAIBTTaskNodes::~UtilityAIBTTaskNodes() { 9 | } 10 | 11 | void UtilityAIBTTaskNodes::_bind_methods() { 12 | } 13 | -------------------------------------------------------------------------------- /src/behaviour_tree/task_nodes.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIBTTaskNodes_H_INCLUDED 2 | #define UtilityAIBTTaskNodes_H_INCLUDED 3 | 4 | #include "nodes.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIBTTaskNodes : public UtilityAIBehaviourTreeNodes { 10 | GDCLASS(UtilityAIBTTaskNodes, UtilityAIBehaviourTreeNodes) 11 | 12 | private: 13 | protected: 14 | static void _bind_methods(); 15 | 16 | public: 17 | UtilityAIBTTaskNodes(); 18 | ~UtilityAIBTTaskNodes(); 19 | }; 20 | 21 | } //namespace godot 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/debugger/debugger_inspector.h: -------------------------------------------------------------------------------- 1 | #ifdef DEBUG_ENABLED 2 | 3 | #endif // debug enabled -------------------------------------------------------------------------------- /src/editor/editor_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_AI_EDITOR_PLUGIN_H_INCLUDED 2 | #define UTILITY_AI_EDITOR_PLUGIN_H_INCLUDED 3 | 4 | #ifdef DEBUG_ENABLED 5 | 6 | #include "../behaviour_tree/nodes.h" 7 | #include "../debugger/debugger_plugin.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | namespace godot { 20 | 21 | class UtilityAIEditorPlugin : public EditorPlugin { 22 | GDCLASS(UtilityAIEditorPlugin, EditorPlugin) 23 | 24 | private: 25 | Node *_editor_scene; 26 | EditorInterface *_editor_interface; 27 | EditorSelection *_editor_selection; 28 | 29 | // UI nodes. 30 | Tree *_node_tree; 31 | 32 | // Debugger. 33 | Ref _debugger; 34 | Ref _debugger_session; 35 | 36 | protected: 37 | static void _bind_methods(); 38 | 39 | void btree_add_child_nodes(Tree *tree, TreeItem *parent_node, UtilityAIBehaviourTreeNodes *parent_ai_node); 40 | 41 | public: 42 | UtilityAIEditorPlugin(); 43 | ~UtilityAIEditorPlugin(); 44 | 45 | // Godot virtuals. 46 | //void _enter_tree() override; 47 | //void _exit_tree() override; 48 | bool _has_main_screen() const override { return true; }; 49 | void _make_visible(bool visible) override {}; 50 | String _get_plugin_name() const override { return String("Utility AI Editor"); }; 51 | void _notification(int p_what); // override; 52 | 53 | // Signal handlers. 54 | 55 | void _on_selection_changed(); 56 | 57 | // Getters and setters for attributes. 58 | // todo: code 59 | }; 60 | 61 | } //namespace godot 62 | 63 | #endif //debug enabled 64 | 65 | #endif -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/angle_to_vector2.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIAngleToVector2SearchCriterion_H_INCLUDED 2 | #define UtilityAIAngleToVector2SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIAngleToVector2SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIAngleToVector2SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | float _min_angle_degrees; 13 | float _max_angle_degrees; 14 | 15 | float _min_angle_radians; 16 | float _max_angle_radians; 17 | 18 | float _span_radians; 19 | float _one_over_span_radians; 20 | 21 | Vector2 _angle_to_direction_vector; 22 | 23 | protected: 24 | static void _bind_methods(); 25 | virtual void _initialize_criterion() override; 26 | 27 | public: 28 | UtilityAIAngleToVector2SearchCriterion(); 29 | ~UtilityAIAngleToVector2SearchCriterion(); 30 | 31 | // Getters and setters for attributes. 32 | 33 | void set_angle_to_direction_vector(Vector2 angle_to_direction_vector); 34 | Vector2 get_angle_to_direction_vector() const; 35 | 36 | void set_min_angle_degrees(float min_angle_degrees); 37 | float get_min_angle_degrees() const; 38 | 39 | void set_max_angle_degrees(float max_angle_degrees); 40 | float get_max_angle_degrees() const; 41 | 42 | // Handling methods. 43 | 44 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 45 | }; 46 | 47 | } //namespace godot 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/angle_to_vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIAngleToVector3SearchCriterion_H_INCLUDED 2 | #define UtilityAIAngleToVector3SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIAngleToVector3SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIAngleToVector3SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | float _min_angle_degrees; 13 | float _max_angle_degrees; 14 | 15 | float _min_angle_radians; 16 | float _max_angle_radians; 17 | 18 | float _span_radians; 19 | float _one_over_span_radians; 20 | 21 | Vector3 _angle_to_direction_vector; 22 | 23 | protected: 24 | static void _bind_methods(); 25 | virtual void _initialize_criterion() override; 26 | 27 | public: 28 | UtilityAIAngleToVector3SearchCriterion(); 29 | ~UtilityAIAngleToVector3SearchCriterion(); 30 | 31 | // Getters and setters for attributes. 32 | 33 | void set_angle_to_direction_vector(Vector3 angle_to_direction_vector); 34 | Vector3 get_angle_to_direction_vector() const; 35 | 36 | void set_min_angle_degrees(float min_angle_degrees); 37 | float get_min_angle_degrees() const; 38 | 39 | void set_max_angle_degrees(float max_angle_degrees); 40 | float get_max_angle_degrees() const; 41 | 42 | // Handling methods. 43 | 44 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 45 | }; 46 | 47 | } //namespace godot 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/angle_to_vector3_xz.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIAngleToVector3XZSearchCriterion_H_INCLUDED 2 | #define UtilityAIAngleToVector3XZSearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIAngleToVector3XZSearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIAngleToVector3XZSearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | float _min_angle_degrees; 13 | float _max_angle_degrees; 14 | 15 | float _min_angle_radians; 16 | float _max_angle_radians; 17 | 18 | float _span_radians; 19 | float _one_over_span_radians; 20 | 21 | Vector3 _angle_to_direction_vector; 22 | Vector2 _xz_angle_vector; 23 | 24 | protected: 25 | static void _bind_methods(); 26 | virtual void _initialize_criterion() override; 27 | 28 | public: 29 | UtilityAIAngleToVector3XZSearchCriterion(); 30 | ~UtilityAIAngleToVector3XZSearchCriterion(); 31 | 32 | // Getters and setters for attributes. 33 | 34 | void set_angle_to_direction_vector(Vector3 angle_to_direction_vector); 35 | Vector3 get_angle_to_direction_vector() const; 36 | 37 | void set_min_angle_degrees(float min_angle_degrees); 38 | float get_min_angle_degrees() const; 39 | 40 | void set_max_angle_degrees(float max_angle_degrees); 41 | float get_max_angle_degrees() const; 42 | 43 | // Handling methods. 44 | 45 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 46 | }; 47 | 48 | } //namespace godot 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/custom.cpp: -------------------------------------------------------------------------------- 1 | #include "custom.h" 2 | 3 | using namespace godot; 4 | 5 | void UtilityAICustomSearchCriterion::_bind_methods() { 6 | } 7 | 8 | UtilityAICustomSearchCriterion::UtilityAICustomSearchCriterion() { 9 | } 10 | 11 | UtilityAICustomSearchCriterion::~UtilityAICustomSearchCriterion() { 12 | } 13 | 14 | void UtilityAICustomSearchCriterion::apply_criterion(Node *node, bool &filter_out, float &score) { 15 | _score = 1.0f; 16 | _is_filtered = false; 17 | if (!has_method("apply_criterion")) 18 | return; 19 | call("apply_criterion", node); 20 | filter_out = _is_filtered; 21 | score = _score; 22 | } -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/custom.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAICustomSearchCriterion_H_INCLUDED 2 | #define UtilityAICustomSearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAICustomSearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAICustomSearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | protected: 13 | static void _bind_methods(); 14 | 15 | public: 16 | UtilityAICustomSearchCriterion(); 17 | ~UtilityAICustomSearchCriterion(); 18 | 19 | // Getters and setters for attributes. 20 | 21 | // Handling methods. 22 | 23 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 24 | }; 25 | 26 | } //namespace godot 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/distance_to_node2d.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDistanceToNode2DSearchCriterion_H_INCLUDED 2 | #define UtilityAIDistanceToNode2DSearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIDistanceToNode2DSearchCriterion : public UtilityAINQSSearchCriteria { 11 | GDCLASS(UtilityAIDistanceToNode2DSearchCriterion, UtilityAINQSSearchCriteria) 12 | 13 | private: 14 | float _min_distance; 15 | float _max_distance; 16 | 17 | float _min_distance_squared; 18 | float _max_distance_squared; 19 | float _span_length; 20 | float _one_over_span_length; 21 | 22 | Node2D *_distance_to; 23 | 24 | protected: 25 | static void _bind_methods(); 26 | virtual void _initialize_criterion() override; 27 | 28 | public: 29 | UtilityAIDistanceToNode2DSearchCriterion(); 30 | ~UtilityAIDistanceToNode2DSearchCriterion(); 31 | 32 | // Getters and setters for attributes. 33 | 34 | void set_distance_to(Node2D *distance_to); 35 | Node2D *get_distance_to() const; 36 | 37 | void set_min_distance(float min_distance); 38 | float get_min_distance() const; 39 | 40 | void set_max_distance(float max_distance); 41 | float get_max_distance() const; 42 | 43 | // Handling methods. 44 | 45 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 46 | }; 47 | 48 | } //namespace godot 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/distance_to_node3d.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDistanceToNode3DSearchCriterion_H_INCLUDED 2 | #define UtilityAIDistanceToNode3DSearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIDistanceToNode3DSearchCriterion : public UtilityAINQSSearchCriteria { 11 | GDCLASS(UtilityAIDistanceToNode3DSearchCriterion, UtilityAINQSSearchCriteria) 12 | 13 | private: 14 | float _min_distance; 15 | float _max_distance; 16 | 17 | float _min_distance_squared; 18 | float _max_distance_squared; 19 | float _span_length; 20 | float _one_over_span_length; 21 | 22 | Node3D *_distance_to; 23 | 24 | protected: 25 | static void _bind_methods(); 26 | virtual void _initialize_criterion() override; 27 | 28 | public: 29 | UtilityAIDistanceToNode3DSearchCriterion(); 30 | ~UtilityAIDistanceToNode3DSearchCriterion(); 31 | 32 | // Getters and setters for attributes. 33 | 34 | void set_distance_to(Node3D *distance_to); 35 | Node3D *get_distance_to() const; 36 | 37 | void set_min_distance(float min_distance); 38 | float get_min_distance() const; 39 | 40 | void set_max_distance(float max_distance); 41 | float get_max_distance() const; 42 | 43 | // Handling methods. 44 | 45 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 46 | }; 47 | 48 | } //namespace godot 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/distance_to_vector2.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDistanceToVector2SearchCriterion_H_INCLUDED 2 | #define UtilityAIDistanceToVector2SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDistanceToVector2SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIDistanceToVector2SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | float _min_distance; 13 | float _max_distance; 14 | 15 | float _min_distance_squared; 16 | float _max_distance_squared; 17 | float _span_length; 18 | float _one_over_span_length; 19 | 20 | Vector2 _distance_to_vector; 21 | 22 | protected: 23 | static void _bind_methods(); 24 | virtual void _initialize_criterion() override; 25 | 26 | public: 27 | UtilityAIDistanceToVector2SearchCriterion(); 28 | ~UtilityAIDistanceToVector2SearchCriterion(); 29 | 30 | // Getters and setters for attributes. 31 | 32 | void set_distance_to_vector(Vector2 distance_to_vector); 33 | Vector2 get_distance_to_vector() const; 34 | 35 | void set_min_distance(float min_distance); 36 | float get_min_distance() const; 37 | 38 | void set_max_distance(float max_distance); 39 | float get_max_distance() const; 40 | 41 | // Handling methods. 42 | 43 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 44 | }; 45 | 46 | } //namespace godot 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/distance_to_vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDistanceToVector3SearchCriterion_H_INCLUDED 2 | #define UtilityAIDistanceToVector3SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDistanceToVector3SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIDistanceToVector3SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | float _min_distance; 13 | float _max_distance; 14 | 15 | float _min_distance_squared; 16 | float _max_distance_squared; 17 | float _span_length; 18 | float _one_over_span_length; 19 | 20 | Vector3 _distance_to_vector; 21 | 22 | protected: 23 | static void _bind_methods(); 24 | virtual void _initialize_criterion() override; 25 | 26 | public: 27 | UtilityAIDistanceToVector3SearchCriterion(); 28 | ~UtilityAIDistanceToVector3SearchCriterion(); 29 | 30 | // Getters and setters for attributes. 31 | 32 | void set_distance_to_vector(Vector3 distance_to_vector); 33 | Vector3 get_distance_to_vector() const; 34 | 35 | void set_min_distance(float min_distance); 36 | float get_min_distance() const; 37 | 38 | void set_max_distance(float max_distance); 39 | float get_max_distance() const; 40 | 41 | // Handling methods. 42 | 43 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 44 | }; 45 | 46 | } //namespace godot 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/dot_product_to_position_vector2.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDotProductToPositionVector2SearchCriterion_H_INCLUDED 2 | #define UtilityAIDotProductToPositionVector2SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDotProductToPositionVector2SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIDotProductToPositionVector2SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | Vector2 _dot_product_position_vector; 13 | float _filtering_value; 14 | int _filtering_rule; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | virtual void _initialize_criterion() override; 19 | 20 | public: 21 | UtilityAIDotProductToPositionVector2SearchCriterion(); 22 | ~UtilityAIDotProductToPositionVector2SearchCriterion(); 23 | 24 | enum UtilityAIDotProductToPositionVector2SearchCriteriaFilteringRule { 25 | LessThan = 0, 26 | LessOrEqual = 1, 27 | Equal = 2, 28 | MoreOrEqual = 3, 29 | MoreThan = 4, 30 | }; 31 | 32 | // Getters and setters for attributes. 33 | 34 | void set_dot_product_position_vector(Vector2 dot_product_position_vector); 35 | Vector2 get_dot_product_position_vector() const; 36 | 37 | void set_filtering_value(float filtering_value); 38 | float get_filtering_value() const; 39 | 40 | void set_filtering_rule(int filtering_rule); 41 | int get_filtering_rule() const; 42 | 43 | // Handling methods. 44 | 45 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 46 | }; 47 | 48 | } //namespace godot 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/dot_product_to_position_vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDotProductToPositionVector3SearchCriterion_H_INCLUDED 2 | #define UtilityAIDotProductToPositionVector3SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDotProductToPositionVector3SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIDotProductToPositionVector3SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | Vector3 _dot_product_position_vector; 13 | float _filtering_value; 14 | int _filtering_rule; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | virtual void _initialize_criterion() override; 19 | 20 | public: 21 | UtilityAIDotProductToPositionVector3SearchCriterion(); 22 | ~UtilityAIDotProductToPositionVector3SearchCriterion(); 23 | 24 | enum UtilityAIDotProductToPositionVector3SearchCriteriaFilteringRule { 25 | LessThan = 0, 26 | LessOrEqual = 1, 27 | Equal = 2, 28 | MoreOrEqual = 3, 29 | MoreThan = 4, 30 | }; 31 | 32 | // Getters and setters for attributes. 33 | 34 | void set_dot_product_position_vector(Vector3 dot_product_position_vector); 35 | Vector3 get_dot_product_position_vector() const; 36 | 37 | void set_filtering_value(float filtering_value); 38 | float get_filtering_value() const; 39 | 40 | void set_filtering_rule(int filtering_rule); 41 | int get_filtering_rule() const; 42 | 43 | // Handling methods. 44 | 45 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 46 | }; 47 | 48 | } //namespace godot 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/dot_product_vector2.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDotProductVector2SearchCriterion_H_INCLUDED 2 | #define UtilityAIDotProductVector2SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDotProductVector2SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIDotProductVector2SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | Vector2 _dot_product_direction_vector; 13 | float _filtering_value; 14 | int _filtering_rule; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | virtual void _initialize_criterion() override; 19 | 20 | public: 21 | UtilityAIDotProductVector2SearchCriterion(); 22 | ~UtilityAIDotProductVector2SearchCriterion(); 23 | 24 | enum UtilityAIDotProductVector2SearchCriteriaFilteringRule { 25 | LessThan = 0, 26 | LessOrEqual = 1, 27 | Equal = 2, 28 | MoreOrEqual = 3, 29 | MoreThan = 4, 30 | }; 31 | 32 | // Getters and setters for attributes. 33 | 34 | void set_dot_product_direction_vector(Vector2 dot_product_direction_vector); 35 | Vector2 get_dot_product_direction_vector() const; 36 | 37 | void set_filtering_value(float filtering_value); 38 | float get_filtering_value() const; 39 | 40 | void set_filtering_rule(int filtering_rule); 41 | int get_filtering_rule() const; 42 | 43 | // Handling methods. 44 | 45 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 46 | }; 47 | 48 | } //namespace godot 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/dot_product_vector3.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIDotProductVector3SearchCriterion_H_INCLUDED 2 | #define UtilityAIDotProductVector3SearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIDotProductVector3SearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIDotProductVector3SearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | Vector3 _dot_product_direction_vector; 13 | float _filtering_value; 14 | int _filtering_rule; 15 | 16 | protected: 17 | static void _bind_methods(); 18 | virtual void _initialize_criterion() override; 19 | 20 | public: 21 | UtilityAIDotProductVector3SearchCriterion(); 22 | ~UtilityAIDotProductVector3SearchCriterion(); 23 | 24 | enum UtilityAIDotProductVector3SearchCriteriaFilteringRule { 25 | LessThan = 0, 26 | LessOrEqual = 1, 27 | Equal = 2, 28 | MoreOrEqual = 3, 29 | MoreThan = 4, 30 | }; 31 | 32 | // Getters and setters for attributes. 33 | 34 | void set_dot_product_direction_vector(Vector3 dot_product_direction_vector); 35 | Vector3 get_dot_product_direction_vector() const; 36 | 37 | void set_filtering_value(float filtering_value); 38 | float get_filtering_value() const; 39 | 40 | void set_filtering_rule(int filtering_rule); 41 | int get_filtering_rule() const; 42 | 43 | // Handling methods. 44 | 45 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 46 | }; 47 | 48 | } //namespace godot 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/metadata.cpp: -------------------------------------------------------------------------------- 1 | #include "metadata.h" 2 | 3 | using namespace godot; 4 | 5 | UtilityAIMetadataSearchCriterion::UtilityAIMetadataSearchCriterion() { 6 | } 7 | 8 | UtilityAIMetadataSearchCriterion::~UtilityAIMetadataSearchCriterion() { 9 | } 10 | 11 | void UtilityAIMetadataSearchCriterion::_bind_methods() { 12 | ClassDB::bind_method(D_METHOD("set_metadata_name", "metadata_name"), &UtilityAIMetadataSearchCriterion::set_metadata_name); 13 | ClassDB::bind_method(D_METHOD("get_metadata_name"), &UtilityAIMetadataSearchCriterion::get_metadata_name); 14 | ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "metadata_name", PROPERTY_HINT_NONE), "set_metadata_name", "get_metadata_name"); 15 | 16 | ClassDB::bind_method(D_METHOD("set_metadata_value", "metadata_value"), &UtilityAIMetadataSearchCriterion::set_metadata_value); 17 | ClassDB::bind_method(D_METHOD("get_metadata_value"), &UtilityAIMetadataSearchCriterion::get_metadata_value); 18 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "metadata_value", PROPERTY_HINT_NONE), "set_metadata_value", "get_metadata_value"); 19 | } 20 | 21 | // Getters and setters. 22 | 23 | void UtilityAIMetadataSearchCriterion::set_metadata_name(StringName metadata_name) { 24 | _metadata_name = metadata_name; 25 | } 26 | 27 | StringName UtilityAIMetadataSearchCriterion::get_metadata_name() const { 28 | return _metadata_name; 29 | } 30 | 31 | void UtilityAIMetadataSearchCriterion::set_metadata_value(Variant metadata_value) { 32 | _metadata_value = metadata_value; 33 | } 34 | 35 | Variant UtilityAIMetadataSearchCriterion::get_metadata_value() const { 36 | return _metadata_value; 37 | } 38 | 39 | void UtilityAIMetadataSearchCriterion::apply_criterion(Node *node, bool &filter_out, float &score) { 40 | _score = 1.0f; 41 | _is_filtered = false; 42 | godot::Variant metavar = node->get_meta(_metadata_name); 43 | _is_filtered = (metavar != _metadata_value); 44 | filter_out = _is_filtered; 45 | score = _score; 46 | } -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/metadata.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIMetadataSearchCriterion_H_INCLUDED 2 | #define UtilityAIMetadataSearchCriterion_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | 6 | namespace godot { 7 | 8 | class UtilityAIMetadataSearchCriterion : public UtilityAINQSSearchCriteria { 9 | GDCLASS(UtilityAIMetadataSearchCriterion, UtilityAINQSSearchCriteria) 10 | 11 | private: 12 | StringName _metadata_name; 13 | Variant _metadata_value; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | public: 19 | UtilityAIMetadataSearchCriterion(); 20 | ~UtilityAIMetadataSearchCriterion(); 21 | 22 | // Getters and setters for attributes. 23 | 24 | void set_metadata_name(StringName metadata_name); 25 | StringName get_metadata_name() const; 26 | 27 | void set_metadata_value(Variant metadata_value); 28 | Variant get_metadata_value() const; 29 | 30 | // Handling methods. 31 | 32 | virtual void apply_criterion(Node *node, bool &filter_out, float &score) override; 33 | }; 34 | 35 | } //namespace godot 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/node_query_system/search_criteria/nqs.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAINQSSearchCriterias_H_INCLUDED 2 | #define UtilityAINQSSearchCriterias_H_INCLUDED 3 | #include "../utility_ai.h" 4 | //#include "node_query_system.h" 5 | //#include 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAINQSSearchCriteria : public UtilityAI { //NodeQuerySystem { 11 | GDCLASS(UtilityAINQSSearchCriteria, UtilityAI) //NodeQuerySystem ) 12 | 13 | private: 14 | bool _use_for_scoring; 15 | bool _use_for_filtering; 16 | 17 | Ref _activation_curve; 18 | 19 | protected: 20 | static void _bind_methods(); 21 | 22 | virtual void _initialize_criterion() {}; 23 | 24 | float _score; 25 | bool _is_filtered; 26 | 27 | public: 28 | UtilityAINQSSearchCriteria(); 29 | ~UtilityAINQSSearchCriteria(); 30 | 31 | // Godot virtuals. 32 | void _ready() override; 33 | 34 | // Getters and setters for attributes. 35 | 36 | void set_use_for_scoring(bool use_for_scoring); 37 | bool get_use_for_scoring() const; 38 | 39 | void set_use_for_filtering(bool use_for_filtering); 40 | bool get_use_for_filtering() const; 41 | 42 | void set_is_filtered(bool is_filtered); 43 | bool get_is_filtered() const; 44 | 45 | void set_score(float score); 46 | float get_score() const; 47 | 48 | void set_activation_curve(Ref activation_curve); 49 | Ref get_activation_curve() const; 50 | 51 | // Handling methods. 52 | 53 | virtual void apply_criterion(Node *node, bool &filter_out, float &score); 54 | virtual float sample_activation_curve(float input_value) const; 55 | }; 56 | 57 | } //namespace godot 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/node_query_system/search_spaces/area2d.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIArea2DSearchSpace_H_INCLUDED 2 | #define UtilityAIArea2DSearchSpace_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIArea2DSearchSpace : public UtilityAINQSSearchSpaces { 10 | GDCLASS(UtilityAIArea2DSearchSpace, UtilityAINQSSearchSpaces) 11 | 12 | private: 13 | Area2D *_area2d; 14 | 15 | TypedArray _intersecting_areas; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | 20 | virtual void _initialize_search_space() override; 21 | virtual void _uninitialize_search_space() override; 22 | 23 | public: 24 | UtilityAIArea2DSearchSpace(); 25 | ~UtilityAIArea2DSearchSpace(); 26 | 27 | void on_area_entered(Area2D *area); 28 | void on_area_exited(Area2D *area); 29 | 30 | // Getters and setters for attributes. 31 | 32 | void set_area2d(Area2D *area2d); 33 | Area2D *get_area2d() const; 34 | 35 | void set_intersecting_areas(TypedArray intersecting_areas); 36 | TypedArray get_intersecting_areas() const; 37 | 38 | virtual TypedArray get_searchspace_nodes() const override; 39 | }; 40 | 41 | } //namespace godot 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/node_query_system/search_spaces/area3d.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAIArea3DSearchSpace_H_INCLUDED 2 | #define UtilityAIArea3DSearchSpace_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAIArea3DSearchSpace : public UtilityAINQSSearchSpaces { 10 | GDCLASS(UtilityAIArea3DSearchSpace, UtilityAINQSSearchSpaces) 11 | 12 | private: 13 | Area3D *_area3d; 14 | 15 | TypedArray _intersecting_areas; 16 | 17 | protected: 18 | static void _bind_methods(); 19 | 20 | virtual void _initialize_search_space() override; 21 | virtual void _uninitialize_search_space() override; 22 | 23 | public: 24 | UtilityAIArea3DSearchSpace(); 25 | ~UtilityAIArea3DSearchSpace(); 26 | 27 | void on_area_entered(Area3D *area); 28 | void on_area_exited(Area3D *area); 29 | 30 | // Getters and setters for attributes. 31 | 32 | void set_area3d(Area3D *area3d); 33 | Area3D *get_area3d() const; 34 | 35 | void set_intersecting_areas(TypedArray intersecting_areas); 36 | TypedArray get_intersecting_areas() const; 37 | 38 | virtual TypedArray get_searchspace_nodes() const override; 39 | }; 40 | 41 | } //namespace godot 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/node_query_system/search_spaces/node_children.cpp: -------------------------------------------------------------------------------- 1 | #include "node_children.h" 2 | #include 3 | #include 4 | 5 | using namespace godot; 6 | 7 | UtilityAINodeChildrenSearchSpace::UtilityAINodeChildrenSearchSpace() { 8 | _parent_node = nullptr; 9 | } 10 | 11 | UtilityAINodeChildrenSearchSpace::~UtilityAINodeChildrenSearchSpace() { 12 | } 13 | 14 | void UtilityAINodeChildrenSearchSpace::_bind_methods() { 15 | ClassDB::bind_method(D_METHOD("set_parent_node", "parent_node"), &UtilityAINodeChildrenSearchSpace::set_parent_node); 16 | ClassDB::bind_method(D_METHOD("get_parent_node"), &UtilityAINodeChildrenSearchSpace::get_parent_node); 17 | ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "parent_node", PROPERTY_HINT_NODE_TYPE, "Node"), "set_parent_node", "get_parent_node"); 18 | } 19 | 20 | void UtilityAINodeChildrenSearchSpace::_initialize_search_space() { 21 | } 22 | 23 | void UtilityAINodeChildrenSearchSpace::_uninitialize_search_space() { 24 | _parent_node = nullptr; 25 | } 26 | 27 | // Getters and setters. 28 | 29 | void UtilityAINodeChildrenSearchSpace::set_parent_node(Node *parent_node) { 30 | _parent_node = parent_node; 31 | } 32 | 33 | Node *UtilityAINodeChildrenSearchSpace::get_parent_node() const { 34 | return _parent_node; 35 | } 36 | 37 | TypedArray UtilityAINodeChildrenSearchSpace::get_searchspace_nodes() const { 38 | if (_parent_node == nullptr || !UtilityFunctions::is_instance_valid(_parent_node)) { 39 | TypedArray emptyarray; 40 | return emptyarray; 41 | } 42 | return _parent_node->get_children(); 43 | } 44 | 45 | /** 46 | void UtilityAINodeChildrenSearchSpace::_ready() { 47 | //if( !get_is_active() ) return; 48 | if( Engine::get_singleton()->is_editor_hint() ) return; 49 | 50 | //_parent_node = get_node_or_null(_parent_node_path); 51 | 52 | } 53 | /**/ 54 | -------------------------------------------------------------------------------- /src/node_query_system/search_spaces/node_children.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAINodeChildrenSearchSpace_H_INCLUDED 2 | #define UtilityAINodeChildrenSearchSpace_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAINodeChildrenSearchSpace : public UtilityAINQSSearchSpaces { 10 | GDCLASS(UtilityAINodeChildrenSearchSpace, UtilityAINQSSearchSpaces) 11 | 12 | private: 13 | Node *_parent_node; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | virtual void _initialize_search_space() override; 19 | virtual void _uninitialize_search_space() override; 20 | 21 | public: 22 | UtilityAINodeChildrenSearchSpace(); 23 | ~UtilityAINodeChildrenSearchSpace(); 24 | 25 | // Getters and setters for attributes. 26 | void set_parent_node(Node *parent); 27 | Node *get_parent_node() const; 28 | 29 | virtual TypedArray get_searchspace_nodes() const override; 30 | 31 | // Godot virtuals. 32 | //void _ready(); 33 | }; 34 | 35 | } //namespace godot 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/node_query_system/search_spaces/node_group.cpp: -------------------------------------------------------------------------------- 1 | #include "node_group.h" 2 | #include 3 | 4 | using namespace godot; 5 | 6 | UtilityAINodeGroupSearchSpace::UtilityAINodeGroupSearchSpace() { 7 | _group_name = ""; 8 | } 9 | 10 | UtilityAINodeGroupSearchSpace::~UtilityAINodeGroupSearchSpace() { 11 | } 12 | 13 | void UtilityAINodeGroupSearchSpace::_bind_methods() { 14 | ClassDB::bind_method(D_METHOD("set_group_name", "group_name"), &UtilityAINodeGroupSearchSpace::set_group_name); 15 | ClassDB::bind_method(D_METHOD("get_group_name"), &UtilityAINodeGroupSearchSpace::get_group_name); 16 | ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "group_name", PROPERTY_HINT_NONE), "set_group_name", "get_group_name"); 17 | } 18 | 19 | // Getters and setters. 20 | 21 | void UtilityAINodeGroupSearchSpace::set_group_name(StringName group_name) { 22 | _group_name = group_name; 23 | } 24 | 25 | StringName UtilityAINodeGroupSearchSpace::get_group_name() const { 26 | return _group_name; 27 | } 28 | 29 | TypedArray UtilityAINodeGroupSearchSpace::get_searchspace_nodes() const { 30 | return get_tree()->get_nodes_in_group(_group_name); 31 | } 32 | -------------------------------------------------------------------------------- /src/node_query_system/search_spaces/node_group.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAINodeGroupSearchSpace_H_INCLUDED 2 | #define UtilityAINodeGroupSearchSpace_H_INCLUDED 3 | 4 | #include "nqs.h" 5 | #include 6 | 7 | namespace godot { 8 | 9 | class UtilityAINodeGroupSearchSpace : public UtilityAINQSSearchSpaces { 10 | GDCLASS(UtilityAINodeGroupSearchSpace, UtilityAINQSSearchSpaces) 11 | 12 | private: 13 | StringName _group_name; 14 | 15 | protected: 16 | static void _bind_methods(); 17 | 18 | public: 19 | UtilityAINodeGroupSearchSpace(); 20 | ~UtilityAINodeGroupSearchSpace(); 21 | 22 | // Getters and setters for attributes. 23 | void set_group_name(StringName group_name); 24 | StringName get_group_name() const; 25 | 26 | virtual TypedArray get_searchspace_nodes() const override; 27 | }; 28 | 29 | } //namespace godot 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/register_types.h: -------------------------------------------------------------------------------- 1 | #ifndef GDUTILITY_AI_REGISTER_TYPES_H 2 | #define GDUTILITY_AI_REGISTER_TYPES_H 3 | 4 | void initialize_utility_ai_module(); 5 | void uninitialize_utility_ai_module(); 6 | 7 | #endif // GDUTILITY_AI_REGISTER_TYPES_H 8 | -------------------------------------------------------------------------------- /src/resources/considerations/consideration_group_resource.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_AI_CONSIDERATION_GROUP_RESOURCE_H_INCLUDED 2 | #define UTILITY_AI_CONSIDERATION_GROUP_RESOURCE_H_INCLUDED 3 | 4 | #include "consideration_resources.h" 5 | 6 | //#include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIConsiderationGroupResource : public UtilityAIConsiderationResources { 11 | GDCLASS(UtilityAIConsiderationGroupResource, UtilityAIConsiderationResources) 12 | 13 | private: 14 | TypedArray _child_nodes; 15 | int _evaluation_method; 16 | bool _invert_score; 17 | 18 | protected: 19 | static void _bind_methods(); 20 | 21 | public: 22 | UtilityAIConsiderationGroupResource(); 23 | ~UtilityAIConsiderationGroupResource(); 24 | 25 | // Getters and setters for attributes. 26 | 27 | void set_evaluation_method(int evaluation_method); 28 | int get_evaluation_method() const; 29 | 30 | enum UtilityAIConsiderationGroupResourceEvaluationMethod { 31 | Sum = 0, 32 | Min = 1, 33 | Max = 2, 34 | Mean = 3, 35 | Multiply = 4, 36 | FirstNonZero = 5, 37 | }; 38 | 39 | void set_invert_score(bool invert_score); 40 | bool get_invert_score() const; 41 | 42 | void set_child_nodes(TypedArray child_nodes); 43 | TypedArray get_child_nodes() const; 44 | 45 | // Handling functions. 46 | 47 | virtual float evaluate(bool &has_vetoed, Node *parent_node) override; 48 | }; 49 | 50 | } //namespace godot 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/resources/considerations/consideration_resource.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_AI_CONSIDERATION_RESOURCE_H_INCLUDED 2 | #define UTILITY_AI_CONSIDERATION_RESOURCE_H_INCLUDED 3 | 4 | #include "../../agent_behaviours/sensors.h" 5 | #include "consideration_resources.h" 6 | #include 7 | #include 8 | 9 | namespace godot { 10 | 11 | class UtilityAIConsiderationResource : public UtilityAIConsiderationResources { 12 | GDCLASS(UtilityAIConsiderationResource, UtilityAIConsiderationResources) 13 | 14 | private: 15 | bool _is_active; 16 | Ref _activation_curve; 17 | UtilityAISensors *_input_sensor; 18 | NodePath _input_sensor_nodepath; // Node pointer doesn't seem to get saved for a resource, so a node path needs to be used. 19 | protected: 20 | static void _bind_methods(); 21 | 22 | public: 23 | UtilityAIConsiderationResource(); 24 | ~UtilityAIConsiderationResource(); 25 | 26 | // Getters and setters for attributes. 27 | 28 | void set_input_sensor_nodepath(NodePath input_sensor_nodepath); 29 | NodePath get_input_sensor_nodepath() const; 30 | 31 | void set_activation_curve(Ref activation_curve); 32 | Ref get_activation_curve() const; 33 | 34 | // Handling methods. 35 | 36 | virtual float evaluate(bool &has_vetoed, Node *parent_node) override; 37 | virtual float sample_activation_curve(float input_value) const; 38 | }; 39 | 40 | } //namespace godot 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/resources/considerations/consideration_resources.cpp: -------------------------------------------------------------------------------- 1 | #include "consideration_resources.h" 2 | 3 | using namespace godot; 4 | 5 | UtilityAIConsiderationResources::UtilityAIConsiderationResources() { 6 | _is_active = true; 7 | //_has_vetoed = false; 8 | } 9 | 10 | UtilityAIConsiderationResources::~UtilityAIConsiderationResources() { 11 | } 12 | 13 | void UtilityAIConsiderationResources::_bind_methods() { 14 | ClassDB::bind_method(D_METHOD("set_is_active", "is_active"), &UtilityAIConsiderationResources::set_is_active); 15 | ClassDB::bind_method(D_METHOD("get_is_active"), &UtilityAIConsiderationResources::get_is_active); 16 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_active", PROPERTY_HINT_NONE), "set_is_active", "get_is_active"); 17 | 18 | //ClassDB::bind_method(D_METHOD("set_has_vetoed", "has_vetoed"), &UtilityAIConsiderationResources::set_has_vetoed); 19 | //ClassDB::bind_method(D_METHOD("get_has_vetoed"), &UtilityAIConsiderationResources::get_has_vetoed); 20 | //ADD_PROPERTY(PropertyInfo(Variant::BOOL, "has_vetoed", PROPERTY_HINT_NONE), "set_has_vetoed","get_has_vetoed"); 21 | } 22 | 23 | // Getters and setters. 24 | 25 | void UtilityAIConsiderationResources::set_is_active(bool is_active) { 26 | _is_active = is_active; 27 | } 28 | 29 | bool UtilityAIConsiderationResources::get_is_active() const { 30 | return _is_active; 31 | } 32 | 33 | /** 34 | void UtilityAIConsiderationResources::set_has_vetoed( bool has_vetoed ) { 35 | _has_vetoed = has_vetoed; 36 | } 37 | bool UtilityAIConsiderationResources::get_has_vetoed() const { 38 | return _has_vetoed; 39 | } 40 | /**/ 41 | 42 | // Handling methods. 43 | 44 | float UtilityAIConsiderationResources::evaluate(bool &has_vetoed, Node *parent_node) { 45 | has_vetoed = false; 46 | return 0.0; 47 | } 48 | -------------------------------------------------------------------------------- /src/resources/considerations/consideration_resources.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILITY_AI_CONSIDERATION_RESOURCES_H_INCLUDED 2 | #define UTILITY_AI_CONSIDERATION_RESOURCES_H_INCLUDED 3 | 4 | #include "../../agent_behaviours/sensors.h" 5 | #include 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAIConsiderationResources : public Resource { 11 | GDCLASS(UtilityAIConsiderationResources, Resource) 12 | 13 | private: 14 | bool _is_active; 15 | //bool _has_vetoed; 16 | protected: 17 | static void _bind_methods(); 18 | 19 | public: 20 | UtilityAIConsiderationResources(); 21 | ~UtilityAIConsiderationResources(); 22 | 23 | // Getters and setters for attributes. 24 | /**/ 25 | void set_is_active(bool is_active); 26 | bool get_is_active() const; 27 | 28 | //void set_has_vetoed( bool has_vetoed ); 29 | //bool get_has_vetoed() const; 30 | 31 | // Handling functions. 32 | 33 | virtual float evaluate(bool &has_vetoed, Node *parent_node); 34 | }; 35 | 36 | } //namespace godot 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/state_tree/node.cpp: -------------------------------------------------------------------------------- 1 | #include "node.h" 2 | 3 | /*#include 4 | #include 5 | #include 6 | #include "../performance_monitor_singleton.h" 7 | */ 8 | 9 | using namespace godot; 10 | 11 | // Method binds. 12 | 13 | //void UtilityAISTSelector::_bind_methods() { 14 | 15 | //ADD_SUBGROUP("Debugging",""); 16 | 17 | //ClassDB::bind_method(D_METHOD("set_total_tick_usec", "total_tick_usec"), &UtilityAISTSelector::set_total_tick_usec); 18 | //ClassDB::bind_method(D_METHOD("get_total_tick_usec"), &UtilityAISTSelector::get_total_tick_usec); 19 | //ADD_PROPERTY(PropertyInfo(Variant::INT, "total_tick_usec", PROPERTY_HINT_NONE), "set_total_tick_usec","get_total_tick_usec"); 20 | 21 | //ClassDB::bind_method(D_METHOD("tick", "user_data", "delta"), &UtilityAISTSelector::tick); 22 | //} 23 | 24 | void UtilityAISTNode::_bind_methods() { 25 | } 26 | 27 | // Constructor and destructor. 28 | 29 | UtilityAISTNode::UtilityAISTNode() { 30 | } 31 | 32 | UtilityAISTNode::~UtilityAISTNode() { 33 | } 34 | 35 | // Getters and Setters. 36 | 37 | // Handling functions. 38 | 39 | /** 40 | UtilityAISTNodes* UtilityAISTSelector::_tick(Variant user_data, double delta) { 41 | 42 | // The selector will only consider the state tree nodes. 43 | UtilityAISTNodes* result_state = nullptr; 44 | for( int i = 0; i < get_child_count(); ++i ) { 45 | if( UtilityAISTNodes* stnode = godot::Object::cast_to(get_child(i)) ) { 46 | if( stnode->on_enter_condition( user_data, delta ) ) { 47 | result_state = stnode->_tick(user_data, delta); 48 | if( result_state != nullptr ) { 49 | return result_state; 50 | } 51 | }//endif on_enter_condition returned true 52 | }// endif valid stnode 53 | }//endfor child count 54 | return nullptr; // We shouldn't get here. If we do, there were no child nodes. 55 | } 56 | /**/ 57 | 58 | // Godot virtuals. 59 | //void UtilityAISTNode::_ready() { 60 | // if( Engine::get_singleton()->is_editor_hint() ) return; 61 | // reset(); 62 | //} 63 | -------------------------------------------------------------------------------- /src/state_tree/node.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAISTSelector_H_INCLUDED 2 | #define UtilityAISTSelector_H_INCLUDED 3 | 4 | #include "nodes.h" 5 | //#include 6 | 7 | namespace godot { 8 | 9 | class UtilityAISTNode : public UtilityAIStateTreeNodes { 10 | GDCLASS(UtilityAISTNode, UtilityAIStateTreeNodes) 11 | 12 | private: 13 | protected: 14 | static void _bind_methods(); 15 | 16 | public: 17 | UtilityAISTNode(); 18 | ~UtilityAISTNode(); 19 | }; 20 | 21 | } //namespace godot 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/state_tree/root.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAISTRoot_H_INCLUDED 2 | #define UtilityAISTRoot_H_INCLUDED 3 | 4 | #include "nodes.h" 5 | #include 6 | #include 7 | 8 | namespace godot { 9 | 10 | class UtilityAISTRoot : public UtilityAIStateTreeNodes { 11 | GDCLASS(UtilityAISTRoot, UtilityAIStateTreeNodes) 12 | 13 | private: 14 | #ifdef DEBUG_ENABLED 15 | uint64_t _total_tick_usec; 16 | uint64_t _total_transition_usec; 17 | #endif 18 | TypedArray _active_states; 19 | std::vector _active_states_vector; 20 | 21 | Variant _ai_context; 22 | 23 | protected: 24 | static void _bind_methods(); 25 | std::vector _child_sensors; 26 | unsigned int _num_child_sensors; 27 | 28 | public: 29 | UtilityAISTRoot(); 30 | ~UtilityAISTRoot(); 31 | 32 | // Getters and setters for attributes. 33 | #ifdef DEBUG_ENABLED 34 | uint64_t get_total_tick_usec() const; 35 | void set_total_tick_usec(uint64_t total_tick_usec); 36 | #endif 37 | 38 | TypedArray get_active_states() const; 39 | 40 | //UtilityAIStateTreeNodes* get_active_state() const; 41 | //_active_states 42 | 43 | // Handling functions. 44 | //virtual TypedArray _tick( Variant user_data, float delta) override; 45 | virtual void transition_to(NodePath path_to_node, Variant user_data, float delta) override; 46 | bool try_transition(UtilityAIStateTreeNodes *transition_target_node, Variant user_data, float delta); 47 | 48 | virtual void transition_to_no_params(NodePath path_to_node) override; 49 | bool try_transition_no_params(UtilityAIStateTreeNodes *transition_target_node); 50 | 51 | void tick(Variant user_data, float delta); 52 | void tick_no_params(); 53 | 54 | // Godot virtuals. 55 | void _ready() override; 56 | }; 57 | 58 | } //namespace godot 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/utility_ai.cpp: -------------------------------------------------------------------------------- 1 | #include "utility_ai.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace godot; 8 | 9 | // Method binds. 10 | 11 | void UtilityAI::_bind_methods() { 12 | ClassDB::bind_method(D_METHOD("set_is_active", "is_active"), &UtilityAI::set_is_active); 13 | ClassDB::bind_method(D_METHOD("get_is_active"), &UtilityAI::get_is_active); 14 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "is_active", PROPERTY_HINT_NONE), "set_is_active", "get_is_active"); 15 | } 16 | 17 | // Constructor and destructor. 18 | 19 | UtilityAI::UtilityAI() { 20 | _is_active = true; 21 | } 22 | 23 | UtilityAI::~UtilityAI() { 24 | } 25 | 26 | // Handling functions. 27 | 28 | // Getters and Setters. 29 | 30 | void UtilityAI::set_is_active(bool is_active) { 31 | _is_active = is_active; 32 | } 33 | 34 | bool UtilityAI::get_is_active() const { 35 | return _is_active; 36 | } 37 | -------------------------------------------------------------------------------- /src/utility_ai.h: -------------------------------------------------------------------------------- 1 | #ifndef UtilityAI_H_INCLUDED 2 | #define UtilityAI_H_INCLUDED 3 | 4 | #include 5 | 6 | namespace godot { 7 | 8 | class UtilityAI : public Node { 9 | GDCLASS(UtilityAI, Node) 10 | 11 | private: 12 | bool _is_active; 13 | 14 | protected: 15 | static void _bind_methods(); 16 | 17 | public: 18 | UtilityAI(); 19 | ~UtilityAI(); 20 | 21 | // Getters and setters for attributes. 22 | void set_is_active(bool is_active); 23 | bool get_is_active() const; 24 | }; 25 | 26 | } //namespace godot 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /utility_ai.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JarkkoPar/Utility_AI/ab5a32f3249b0fa0ae994633158c5c4abfdb8a4c/utility_ai.png --------------------------------------------------------------------------------