summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Systems/AI/Actions
diff options
context:
space:
mode:
authorjjesswan <jessica_wan@brown.edu>2024-04-22 21:56:26 -0400
committerjjesswan <jessica_wan@brown.edu>2024-04-22 21:56:26 -0400
commita556b45abf18f1bd509daaf63b66b7d55e9fd291 (patch)
treebc9b8a2d184c12aee236e7f9f276a34b84ca552d /engine-ocean/Game/Systems/AI/Actions
parentcd7c76017a12bb548036571c1ff13e551369d06d (diff)
add engine version
Diffstat (limited to 'engine-ocean/Game/Systems/AI/Actions')
-rw-r--r--engine-ocean/Game/Systems/AI/Actions/btaction.cpp6
-rw-r--r--engine-ocean/Game/Systems/AI/Actions/btaction.h17
-rw-r--r--engine-ocean/Game/Systems/AI/Actions/walkaction.cpp90
-rw-r--r--engine-ocean/Game/Systems/AI/Actions/walkaction.h29
4 files changed, 142 insertions, 0 deletions
diff --git a/engine-ocean/Game/Systems/AI/Actions/btaction.cpp b/engine-ocean/Game/Systems/AI/Actions/btaction.cpp
new file mode 100644
index 0000000..1b35340
--- /dev/null
+++ b/engine-ocean/Game/Systems/AI/Actions/btaction.cpp
@@ -0,0 +1,6 @@
+#include "btaction.h"
+
+BTAction::BTAction()
+{
+
+}
diff --git a/engine-ocean/Game/Systems/AI/Actions/btaction.h b/engine-ocean/Game/Systems/AI/Actions/btaction.h
new file mode 100644
index 0000000..180f72c
--- /dev/null
+++ b/engine-ocean/Game/Systems/AI/Actions/btaction.h
@@ -0,0 +1,17 @@
+#ifndef BTACTION_H
+#define BTACTION_H
+#include "Game/Systems/AI/btnode.h"
+
+class BTAction : public BTNode
+{
+public:
+ BTAction();
+ virtual Status update(float seconds) = 0;
+ virtual void reset() = 0;
+
+private:
+ Status m_status;
+
+};
+
+#endif // BTACTION_H
diff --git a/engine-ocean/Game/Systems/AI/Actions/walkaction.cpp b/engine-ocean/Game/Systems/AI/Actions/walkaction.cpp
new file mode 100644
index 0000000..6a6d116
--- /dev/null
+++ b/engine-ocean/Game/Systems/AI/Actions/walkaction.cpp
@@ -0,0 +1,90 @@
+#include "walkaction.h"
+#include "Game/Components/PathfindComponent.h"
+#include "Game/Components/TransformComponent.h"
+#include "Game/GameObjects/GameObject.h"
+#include "glm/glm.hpp"
+#include <memory>
+
+
+WalkAction::WalkAction(std::string entity_id,
+ std::map<std::string, BlackboardData>& global_blackboard):
+ m_global_blackboard(global_blackboard)
+{
+
+ m_entity_id = entity_id;
+ m_path.clear();
+
+ m_global_blackboard[m_entity_id].conditionData["isPathfinding"].conditionTrue = false;
+ m_global_blackboard[m_entity_id].conditionData["atDestination"].conditionTrue = false;
+ m_global_blackboard[m_entity_id].conditionData["pathfound"].conditionTrue = false;
+
+
+
+
+}
+
+void WalkAction::setPath(glm::vec3 entity_pos){
+ std::cout << "---------SETTING PATHH" << std::endl;
+ m_destination = m_global_blackboard["player"].locationData.currPos;
+ m_path = m_global_blackboard["navmesh"].environment->getComponent<PathfindComponent>()->getPath(glm::vec3(-0.58249, 0, -0.0210782), glm::vec3(19.5371, 0, 1.39167));
+}
+
+// only activates if the previous conditions are true
+Status WalkAction::update(float seconds){
+
+ glm::vec3 pos = m_global_blackboard[m_entity_id].locationData.currPos;
+
+ // get a path if entity is not pathfinding
+ if (!m_global_blackboard[m_entity_id].conditionData["isPathfinding"].conditionTrue &&
+ !m_global_blackboard[m_entity_id].conditionData["atDestination"].conditionTrue &&
+ !m_global_blackboard[m_entity_id].conditionData["pathfound"].conditionTrue){
+ setPath(pos);
+ m_global_blackboard[m_entity_id].conditionData["isPathfinding"].conditionTrue = true;
+ m_global_blackboard[m_entity_id].conditionData["pathfound"].conditionTrue = true;
+
+ }
+
+ if (!m_path.empty()){
+ if (m_global_blackboard[m_entity_id].conditionData["onGround"].conditionTrue){
+ //std::cout << "on ground" << std::endl;
+
+ std::shared_ptr<ModelTransform> temp_mt = std::make_shared<ModelTransform>();
+ temp_mt->setPos(pos);
+ glm::vec3 v = m_path.back();//glm::vec3(m_path.back().x, pos.y, m_path.back().z);
+ glm::vec3 dir = glm::normalize(v-temp_mt->getPos());
+ temp_mt->translate(dir);
+ //std::cout << "v: (" << v.x << ", " << v.y << ", " << v.z << ")" << std::endl;
+ glm::vec3 pos_eps = v + .01f;
+ glm::vec3 neg_eps = v - .01f;
+
+ // pop if entity within a certain episilon of node
+ if (neg_eps.x < temp_mt->getPos().x < pos_eps.x &&
+ neg_eps.z < temp_mt->getPos().z < pos_eps.z){
+ m_path.pop_back();
+ }
+
+ m_global_blackboard[m_entity_id].locationData.setToPos = temp_mt->getPos();
+ }
+
+ return Status::RUNNING;
+ }
+
+ // if reached destination, then walking succeeded
+ if (pos.x == m_destination.x && pos.z == m_destination.z){
+ m_global_blackboard[m_entity_id].conditionData["isPathfinding"].conditionTrue = false;
+ m_global_blackboard[m_entity_id].conditionData["atDestination"].conditionTrue = true;
+ std::cout << "-reached-" << std::endl;
+ return Status::SUCCESS;
+
+ }
+
+ // otherwise
+ m_global_blackboard[m_entity_id].conditionData["isPathfinding"].conditionTrue = false;
+ return Status::FAIL;
+
+}
+
+void WalkAction::reset(){}
+void WalkAction::addChildren(BTNode *node){}
+
+
diff --git a/engine-ocean/Game/Systems/AI/Actions/walkaction.h b/engine-ocean/Game/Systems/AI/Actions/walkaction.h
new file mode 100644
index 0000000..2e24864
--- /dev/null
+++ b/engine-ocean/Game/Systems/AI/Actions/walkaction.h
@@ -0,0 +1,29 @@
+#ifndef WALKACTION_H
+#define WALKACTION_H
+#include "Game/Components/TransformComponent.h"
+#include "Game/GameObjects/GameObject.h"
+#include "Game/Systems/AI/btnode.h"
+#include "glm/fwd.hpp"
+#include <memory>
+#include "btaction.h"
+
+class WalkAction : public BTNode
+{
+public:
+ WalkAction(std::string entity_id, std::map<std::string, BlackboardData>& global_blackboard);
+ Status update(float seconds) override;
+ void reset() override;
+ void setPath(glm::vec3 entity_pos);
+ void addChildren(BTNode *node) override;
+
+
+
+private:
+ std::vector<glm::vec3> m_path;
+ glm::vec3 m_destination;
+ std::map<std::string, BlackboardData>& m_global_blackboard;
+ std::string m_entity_id;
+};
+
+
+#endif // WALKACTION_H