Bud can run and explore buildings
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
#include "stdafx.h"
|
||||
#include "SurvivalAgentPlugin.h"
|
||||
#include "BehaviourTree.h"
|
||||
#include "IExamInterface.h"
|
||||
#include "Blackboard.h"
|
||||
#include "BehaviourTree.h"
|
||||
#include "Behaviour.h"
|
||||
#include "Thinker.h"
|
||||
#include "BigThink.h"
|
||||
|
||||
//Called only once, during initialization
|
||||
void SurvivalAgentPlugin::Initialize(IBaseInterface* pInterface, PluginInfo& info)
|
||||
@@ -18,34 +19,61 @@ void SurvivalAgentPlugin::Initialize(IBaseInterface* pInterface, PluginInfo& inf
|
||||
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,
|
||||
m_Thinker = new Thinker();
|
||||
|
||||
constexpr float closeRadius{ 50.f };
|
||||
const float farRadius{ m_pInterface->World_GetInfo().Dimensions.x };
|
||||
|
||||
const std::string searchTimer{ "Search" };
|
||||
|
||||
Blackboard* blackboardPtr{ CreateBlackboard() };
|
||||
m_BehaviourTree = new BT::BehaviorTree(blackboardPtr,
|
||||
new BT::Selector({
|
||||
new BT::PartialSequence({
|
||||
new BT::Action(BT_Action::FindAHouse),
|
||||
new BT::Action(BT_Action::GoToTarget)
|
||||
})
|
||||
})
|
||||
);
|
||||
BigThink::PurgeZoneHandling(),
|
||||
BigThink::ItemHandling(),
|
||||
BigThink::PickUpHandling(),
|
||||
BigThink::HouseHandling()
|
||||
}));
|
||||
|
||||
|
||||
}
|
||||
|
||||
Blackboard* SurvivalAgentPlugin::CreateBlackboard() {
|
||||
Blackboard* blackboard = new Blackboard();
|
||||
blackboard->AddData("Interface", m_pInterface);
|
||||
blackboard->AddData("Steering", SteeringPlugin_Output{});
|
||||
blackboard->AddData("Target", m_Target);
|
||||
return blackboard;
|
||||
|
||||
Blackboard* blackboardPtr = new Blackboard();
|
||||
|
||||
blackboardPtr->AddData("Brain", m_Thinker);
|
||||
blackboardPtr->AddData("Interface", m_pInterface);
|
||||
blackboardPtr->AddData("Steering", SteeringPlugin_Output{});
|
||||
blackboardPtr->AddData("Target", m_Target);
|
||||
blackboardPtr->AddData("Spin", false);
|
||||
blackboardPtr->AddData("FailSafe", std::chrono::steady_clock::time_point{});
|
||||
blackboardPtr->AddData("MaxFailSafe", 2.f);
|
||||
blackboardPtr->AddData("FailSafeDoOnce", false);
|
||||
|
||||
blackboardPtr->AddData("TargetItem", ItemInfo{});
|
||||
blackboardPtr->AddData("NextFreeSlot", 0);
|
||||
|
||||
blackboardPtr->AddData("TargetHouse", HouseInfo{});
|
||||
blackboardPtr->AddData("TimerBeforeLeaving", std::chrono::steady_clock::time_point{});
|
||||
blackboardPtr->AddData("TimerBeforeLeavingDoOnce", false);
|
||||
blackboardPtr->AddData("MaxTimeBeforeLeaving", 5.f);
|
||||
|
||||
return blackboardPtr;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void SurvivalAgentPlugin::UpdateBlackboard(const SteeringPlugin_Output& steering) {
|
||||
Blackboard* blackboard{ m_BehaviourTree->GetBlackboard() };
|
||||
|
||||
//blackboard->ChangeData("playerPos", m_pInterface->Agent_GetInfo().Position);
|
||||
blackboard->ChangeData("Steering", steering);
|
||||
blackboard->GetData("Target", m_Target);
|
||||
}
|
||||
|
||||
SurvivalAgentPlugin::~SurvivalAgentPlugin() {
|
||||
SAFE_DELETE(m_BehaviourTree);
|
||||
SAFE_DELETE(m_Thinker);
|
||||
}
|
||||
|
||||
//Called only once
|
||||
@@ -80,8 +108,6 @@ void SurvivalAgentPlugin::InitGameDebugParams(GameDebugParams& params)
|
||||
params.Seed = 0; //-1 = don't set seed. Any other number = fixed seed //TIP: use Seed = int(time(nullptr)) for pure randomness
|
||||
}
|
||||
|
||||
//Only Active in DEBUG Mode
|
||||
//(=Use only for Debug Purposes)
|
||||
void SurvivalAgentPlugin::Update_Debug(float dt)
|
||||
{
|
||||
//Demo Event Code
|
||||
@@ -151,21 +177,32 @@ void SurvivalAgentPlugin::Update_Debug(float dt)
|
||||
SteeringPlugin_Output SurvivalAgentPlugin::UpdateSteering(float dt)
|
||||
{
|
||||
auto steering = SteeringPlugin_Output();
|
||||
|
||||
//Use the Interface (IAssignmentInterface) to 'interface' with the AI_Framework
|
||||
auto agentInfo = m_pInterface->Agent_GetInfo();
|
||||
bool spin{};
|
||||
|
||||
UpdateBlackboard(steering);
|
||||
|
||||
m_BehaviourTree->Update();
|
||||
|
||||
m_BehaviourTree->GetBlackboard()->GetData("Steering", steering);
|
||||
m_BehaviourTree->GetBlackboard()->GetData("Spin", spin);
|
||||
|
||||
steering.AngularVelocity = m_AngSpeed;
|
||||
steering.AutoOrient = false;
|
||||
if (spin) {
|
||||
steering.AutoOrient = false;
|
||||
steering.AngularVelocity = 3.14f;
|
||||
}
|
||||
|
||||
if (m_GrabItem) {
|
||||
ItemInfo item;
|
||||
|
||||
m_BehaviourTree->GetBlackboard()->GetData("TargetItem", item);
|
||||
|
||||
if (m_pInterface->GrabItem(item)) {
|
||||
m_pInterface->Inventory_AddItem(m_InventorySlot, item);
|
||||
}
|
||||
}
|
||||
|
||||
return steering;
|
||||
|
||||
}
|
||||
|
||||
//This function should only be used for rendering debug elements
|
||||
|
||||
Reference in New Issue
Block a user