Basic house ah

This commit is contained in:
Bram verhulst
2025-05-18 12:34:25 +02:00
parent 620dafb591
commit 7d797fa207
11 changed files with 443 additions and 115 deletions

View File

@@ -1,8 +1,9 @@
#include "stdafx.h"
#include "SurvivalAgentPlugin.h"
#include "IExamInterface.h"
using namespace std;
#include "Blackboard.h"
#include "BehaviourTree.h"
#include "Behaviour.h"
//Called only once, during initialization
void SurvivalAgentPlugin::Initialize(IBaseInterface* pInterface, PluginInfo& info)
@@ -16,6 +17,35 @@ void SurvivalAgentPlugin::Initialize(IBaseInterface* pInterface, PluginInfo& inf
info.Student_Name = "Bram Verhulst";//No special characters allowed. Highscores won't work with special characters.
info.Student_Class = "2DAE11";
info.LB_Password = "ILikeCuteCats!";//Don't use a real password! This is only to prevent other students from overwriting your highscore!
Blackboard* blackboard = CreateBlackboard();
m_BehaviourTree = new BT::BehaviorTree(blackboard,
new BT::Selector({
new BT::PartialSequence({
new BT::Action(BT_Action::FindAHouse),
new BT::Action(BT_Action::GoToTarget)
})
})
);
}
Blackboard* SurvivalAgentPlugin::CreateBlackboard() {
Blackboard* blackboard = new Blackboard();
blackboard->AddData("Interface", m_pInterface);
blackboard->AddData("Steering", SteeringPlugin_Output{});
blackboard->AddData("Target", m_Target);
return blackboard;
}
void SurvivalAgentPlugin::UpdateBlackboard(const SteeringPlugin_Output& steering) {
Blackboard* blackboard{ m_BehaviourTree->GetBlackboard() };
//blackboard->ChangeData("playerPos", m_pInterface->Agent_GetInfo().Position);
blackboard->ChangeData("Steering", steering);
}
SurvivalAgentPlugin::~SurvivalAgentPlugin() {
SAFE_DELETE(m_BehaviourTree);
}
//Called only once
@@ -125,101 +155,15 @@ SteeringPlugin_Output SurvivalAgentPlugin::UpdateSteering(float dt)
//Use the Interface (IAssignmentInterface) to 'interface' with the AI_Framework
auto agentInfo = m_pInterface->Agent_GetInfo();
UpdateBlackboard(steering);
//Use the navmesh to calculate the next navmesh point
//auto nextTargetPos = m_pInterface->NavMesh_GetClosestPathPoint(checkpointLocation);
m_BehaviourTree->Update();
//OR, Use the mouse target
auto nextTargetPos = m_pInterface->NavMesh_GetClosestPathPoint(m_Target);
m_BehaviourTree->GetBlackboard()->GetData("Steering", steering);
//FOV USAGE DEMO
//===============
steering.AngularVelocity = m_AngSpeed;
steering.AutoOrient = false;
//FOV stats = CHEAP! info about the FOV
FOVStats stats = m_pInterface->FOV_GetStats();
//FOV data (snapshot of the FOV of the current frame) = EXPENSIVE! returns a new vector for every call
auto vHousesInFOV = m_pInterface->GetHousesInFOV();
auto vEnemiesInFOV = m_pInterface->GetEnemiesInFOV();
auto vItemsInFOV = m_pInterface->GetItemsInFOV();
auto vPurgezonesInFOV = m_pInterface->GetPurgeZonesInFOV();
//for (auto& zoneInfo : vPurgezonesInFOV)
//{
// std::cout << "Purge Zone in FOV:" << zoneInfo.Center.x << ", "<< zoneInfo.Center.y << "---Radius: "<< zoneInfo.Radius << std::endl;
//}
//for (auto& enemyInfo : vEnemiesInFOV)
//{
// std::cout << "Enemy in FOV:" << enemyInfo.Location.x << ", " << enemyInfo.Location.y << "---Health: " << enemyInfo.Health << std::endl;
//}
//for (auto& item : vItemsInFOV)
//{
// std::cout << "Item in FOV:" << item.Location.x << ", " << item.Location.y << "---Value: " << item.Value << std::endl;
//}
//INVENTORY USAGE DEMO
//********************
if (m_GrabItem)
{
ItemInfo item;
//Item_Grab > When DebugParams.AutoGrabClosestItem is TRUE, the Item_Grab function returns the closest item in range
//Keep in mind that DebugParams are only used for debugging purposes, by default this flag is FALSE
//Otherwise, use GetEntitiesInFOV() to retrieve a vector of all entities in the FOV (EntityInfo)
//Item_Grab gives you the ItemInfo back, based on the passed EntityHash (retrieved by GetEntitiesInFOV)
if (m_pInterface->GrabNearestItem(item))
{
//Once grabbed, you can add it to a specific inventory slot
//Slot must be empty
m_pInterface->Inventory_AddItem(m_InventorySlot, item);
}
}
if (m_UseItem)
{
//Use an item (make sure there is an item at the given inventory slot)
m_pInterface->Inventory_UseItem(m_InventorySlot);
}
if (m_RemoveItem)
{
//Remove an item from a inventory slot
m_pInterface->Inventory_RemoveItem(m_InventorySlot);
}
if (m_DestroyItemsInFOV)
{
for (auto& item : vItemsInFOV)
{
m_pInterface->DestroyItem(item);
}
}
//Simple Seek Behaviour (towards Target)
steering.LinearVelocity = nextTargetPos - agentInfo.Position; //Desired Velocity
steering.LinearVelocity.Normalize(); //Normalize Desired Velocity
steering.LinearVelocity *= agentInfo.MaxLinearSpeed; //Rescale to Max Speed
if (Distance(nextTargetPos, agentInfo.Position) < 2.f)
{
steering.LinearVelocity = Elite::ZeroVector2;
}
//steering.AngularVelocity = m_AngSpeed; //Rotate your character to inspect the world while walking
steering.AutoOrient = true; //Setting AutoOrient to true overrides the AngularVelocity
steering.RunMode = m_CanRun; //If RunMode is True > MaxLinearSpeed is increased for a limited time (until your stamina runs out)
//SteeringPlugin_Output is works the exact same way a SteeringBehaviour output
//@End (Demo Purposes)
m_GrabItem = false; //Reset State
m_UseItem = false;
m_RemoveItem = false;
m_DestroyItemsInFOV = false;
return steering;
}