we shooting

This commit is contained in:
Bram verhulst
2025-05-27 09:56:10 +02:00
parent d5262a332d
commit 1d2ca4f9ca
11 changed files with 433 additions and 46 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -859,13 +859,13 @@ Size=240,520
Collapsed=0 Collapsed=0
[WORLD INFO [35 FPS]] [WORLD INFO [35 FPS]]
Pos=651,10 Pos=710,10
Size=240,431 Size=240,520
Collapsed=0 Collapsed=0
[WORLD INFO [34 FPS]] [WORLD INFO [34 FPS]]
Pos=651,10 Pos=710,10
Size=240,431 Size=240,520
Collapsed=0 Collapsed=0
[WORLD INFO [33 FPS]] [WORLD INFO [33 FPS]]
@@ -1973,3 +1973,153 @@ Pos=710,10
Size=240,520 Size=240,520
Collapsed=0 Collapsed=0
[WORLD INFO [740 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [454 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [429 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [316 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [303 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [242 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [724 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [401 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [390 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [794 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [32 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [29 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [27 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [25 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [23 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [22 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [20 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [21 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [19 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [18 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [17 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [16 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [15 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [14 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [13 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [12 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [11 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [10 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [754 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [9 FPS]]
Pos=710,10
Size=240,520
Collapsed=0

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -93,7 +93,17 @@ namespace BT_Action
} }
BT::State EnableSpin(Blackboard* blackboardPtr) { BT::State EnableSpin(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
SteeringPlugin_Output steering{};
blackboardPtr->GetData("Interface", interfacePtr);
blackboardPtr->GetData("Steering", steering);
steering.AutoOrient = true;
steering.AngularVelocity = interfacePtr->Agent_GetInfo().MaxAngularSpeed;
blackboardPtr->ChangeData("Spin", true); blackboardPtr->ChangeData("Spin", true);
blackboardPtr->ChangeData("Steering", steering);
return BT::State::Success; return BT::State::Success;
} }
@@ -104,6 +114,7 @@ namespace BT_Action
return BT::State::Success; return BT::State::Success;
} }
BT::State FindClosestEdge(Blackboard* blackboardPtr, int degree) { BT::State FindClosestEdge(Blackboard* blackboardPtr, int degree) {
IExamInterface* interfacePtr{}; IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr); blackboardPtr->GetData("Interface", interfacePtr);
@@ -138,6 +149,106 @@ namespace BT_Action
return BT::State::Success; return BT::State::Success;
} }
BT::State SetZombieTarget(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
if (interfacePtr->GetEnemiesInFOV().capacity() == 0) {
return BT::State::Failure;
}
EnemyInfo zombieInfo{};
float closestZombie{ FLT_MAX };
for (const auto zombie : interfacePtr->GetEnemiesInFOV()) {
const float distance{ interfacePtr->Agent_GetInfo().Position.DistanceSquared(zombie.Location) };
if (closestZombie < distance)
continue;
closestZombie = distance;
zombieInfo = zombie;
}
blackboardPtr->ChangeData("TargetZombie", zombieInfo);
return BT::State::Success;
}
BT::State AvoidingZombie(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
SteeringPlugin_Output steering{};
blackboardPtr->GetData("Interface", interfacePtr);
blackboardPtr->GetData("Steering", steering);
Elite::Vector2 evadeDirection{};
for (auto zombie : interfacePtr->GetEnemiesInFOV()) {
Elite::Vector2 currentPos{ interfacePtr->Agent_GetInfo().Position };
Elite::Vector2 targetPos{ zombie.Location };
Elite::Vector2 goingAwayVec{ currentPos - targetPos };
float distance = goingAwayVec.MagnitudeSquared();
evadeDirection += goingAwayVec / distance;
}
steering.LinearVelocity = evadeDirection.GetNormalized() * interfacePtr->Agent_GetInfo().MaxLinearSpeed;
blackboardPtr->ChangeData("Steering", steering);
return BT::State::Success;
}
BT::State RotateToZombie(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
EnemyInfo zombieInfo{};
SteeringPlugin_Output steering{};
blackboardPtr->GetData("Interface", interfacePtr);
blackboardPtr->GetData("TargetZombie", zombieInfo);
blackboardPtr->GetData("Steering", steering);
const float maxAngularVelocity{ interfacePtr->Agent_GetInfo().MaxAngularSpeed };
const float targetAngle{ VectorToOrientation((zombieInfo.Location - interfacePtr->Agent_GetInfo().Position).GetNormalized()) };
const float angleDiff{ targetAngle - interfacePtr->Agent_GetInfo().Orientation };
steering.AngularVelocity = angleDiff * maxAngularVelocity;
blackboardPtr->ChangeData("Steering", steering);
blackboardPtr->ChangeData("angleDiff", angleDiff);
return BT::State::Success;
}
BT::State ReadyToShoot(Blackboard* blackboardPtr, float minAngleDiff) {
float angleDiff{};
blackboardPtr->GetData("angleDiff", angleDiff);
return (std::abs(angleDiff) < minAngleDiff) ? BT::State::Success : BT::State::Failure;
}
BT::State Shoot(Blackboard* blackboardPtr, eItemType type) {
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
blackboardPtr->GetData("Interface", interfacePtr);
blackboardPtr->GetData("Brain", thinkerPtr);
const auto item = thinkerPtr->FindLeastValueItem(type);
if (item->ItemInfo.Value <= 0)
return BT::State::Failure;
if (interfacePtr->Inventory_UseItem(item->invIndex)) {
--item->ItemInfo.Value;
return BT::State::Success;
}
return BT::State::Failure;
}
BT::State SetItemAsTarget(Blackboard* blackboardPtr) { BT::State SetItemAsTarget(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{}; IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr); blackboardPtr->GetData("Interface", interfacePtr);
@@ -150,12 +261,12 @@ namespace BT_Action
float closestItem{ FLT_MAX }; float closestItem{ FLT_MAX };
for (const auto item : interfacePtr->GetItemsInFOV()) { for (const auto item : interfacePtr->GetItemsInFOV()) {
const float itemDistance{ interfacePtr->Agent_GetInfo().Position.DistanceSquared(item.Location) }; const float distance{ interfacePtr->Agent_GetInfo().Position.DistanceSquared(item.Location) };
if (closestItem < itemDistance) if (closestItem < distance)
continue; continue;
closestItem = itemDistance; closestItem = distance;
targetItem = item; targetItem = item;
} }
@@ -304,6 +415,11 @@ namespace BT_Action
const Elite::Vector2 pointOnCircle{ playerPos.x + searchRadius * std::cosf(TO_RAD(i)), playerPos.y + searchRadius * std::sinf(TO_RAD(i)) }; const Elite::Vector2 pointOnCircle{ playerPos.x + searchRadius * std::cosf(TO_RAD(i)), playerPos.y + searchRadius * std::sinf(TO_RAD(i)) };
const Elite::Vector2 target = interfacePtr->NavMesh_GetClosestPathPoint(pointOnCircle); const Elite::Vector2 target = interfacePtr->NavMesh_GetClosestPathPoint(pointOnCircle);
if (target == Elite::Vector2(400, 400)) {
std::cout << pointOnCircle << std::endl;
}
if (pointOnCircle != target) { if (pointOnCircle != target) {
constexpr float houseOffset{ 5.f }; constexpr float houseOffset{ 5.f };
if (thinkerPtr->CheckIfTargetIsExplored(target, houseOffset)) if (thinkerPtr->CheckIfTargetIsExplored(target, houseOffset))
@@ -319,8 +435,7 @@ namespace BT_Action
} }
if (finalTarget == Elite::Vector2{}) { if (finalTarget == Elite::Vector2{}) {
finalTarget = Elite::Vector2(randNumRange(-searchRadius, searchRadius), return BT::State::Failure;
randNumRange(-searchRadius, searchRadius));
} }
blackboardPtr->ChangeData("Target", finalTarget); blackboardPtr->ChangeData("Target", finalTarget);
@@ -328,6 +443,19 @@ namespace BT_Action
return BT::State::Success; return BT::State::Success;
} }
BT::State FindRandomLocation(Blackboard* blackboardPtr, float randomRadius) {
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
const Elite::Vector2 playerPos{ interfacePtr->Agent_GetInfo().Position };
Elite::Vector2 target = Elite::Vector2(playerPos.x + randNumRange(-randomRadius, randomRadius),
playerPos.y + randNumRange(-randomRadius, randomRadius));
blackboardPtr->ChangeData("Target", target);
return BT::State::Success;
}
BT::State GetHouseAsTarget(Blackboard* blackboardPtr, float maxTravelDistance) { BT::State GetHouseAsTarget(Blackboard* blackboardPtr, float maxTravelDistance) {
IExamInterface* interfacePtr{}; IExamInterface* interfacePtr{};
Thinker* thinkerPtr{}; Thinker* thinkerPtr{};
@@ -418,6 +546,29 @@ namespace BT_Condition
return false; return false;
} }
bool SeeZombie(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
return interfacePtr->GetEnemiesInFOV().capacity() > 0;
}
bool HasWeapon(Blackboard* blackboardPtr) {
return ItemInInv(blackboardPtr, eItemType::SHOTGUN) || ItemInInv(blackboardPtr, eItemType::PISTOL);
}
bool InRange(Blackboard* blackboardPtr, float maxRange) {
IExamInterface* interfacePtr{};
EnemyInfo zombieInfo{};
blackboardPtr->GetData("Interface", interfacePtr);
blackboardPtr->GetData("TargetZombie", zombieInfo);
const float dist2{ (zombieInfo.Location - interfacePtr->Agent_GetInfo().Position).MagnitudeSquared() };
return dist2 <= maxRange * maxRange;
}
bool SeePurgeZone(Blackboard* blackboardPtr) { bool SeePurgeZone(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{}; IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr); blackboardPtr->GetData("Interface", interfacePtr);

View File

@@ -20,6 +20,12 @@ namespace BT_Action
BT::State FindClosestEdge(Blackboard* blackboardPtr, int degree); BT::State FindClosestEdge(Blackboard* blackboardPtr, int degree);
BT::State SetZombieTarget(Blackboard* blackboardPtr);
BT::State AvoidingZombie(Blackboard* blackboardPtr);
BT::State RotateToZombie(Blackboard* blackboardPtr);
BT::State ReadyToShoot(Blackboard* blackboardPtr, float minAngleDiff);
BT::State Shoot(Blackboard* blackboardPtr, eItemType type);
BT::State UseItem(Blackboard* blackboardPtr, eItemType type); BT::State UseItem(Blackboard* blackboardPtr, eItemType type);
BT::State SetItemAsTarget(Blackboard* blackboardPtr); BT::State SetItemAsTarget(Blackboard* blackboardPtr);
@@ -29,11 +35,13 @@ namespace BT_Action
BT::State CheckItem(Blackboard* blackboardPtr); BT::State CheckItem(Blackboard* blackboardPtr);
BT::State TryFindHouse(Blackboard* blackboardPtr, float searchRadius, int degree); BT::State TryFindHouse(Blackboard* blackboardPtr, float searchRadius, int degree);
BT::State FindRandomLocation(Blackboard* blackboardPtr, float randomRadius);
BT::State GetHouseAsTarget(Blackboard* blackboardPtr, float maxTravelDistance); BT::State GetHouseAsTarget(Blackboard* blackboardPtr, float maxTravelDistance);
BT::State CheckHouses(Blackboard* blackboardPtr); BT::State CheckHouses(Blackboard* blackboardPtr);
BT::State SetExpireDate(Blackboard* blackboardPtr); BT::State SetExpireDate(Blackboard* blackboardPtr);
BT::State GetInsideTarget(Blackboard* blackboardPtr, float offset); BT::State GetInsideTarget(Blackboard* blackboardPtr, float offset);
} }
namespace BT_Condition namespace BT_Condition
@@ -43,6 +51,10 @@ namespace BT_Condition
bool SeePurgeZone(Blackboard* blackboardPtr); bool SeePurgeZone(Blackboard* blackboardPtr);
bool SeeZombie(Blackboard* blackboardPtr);
bool HasWeapon(Blackboard* blackboardPtr);
bool InRange(Blackboard* blackboardPtr, float maxRange);
bool ItemInInv(Blackboard* blackboardPtr, eItemType type); bool ItemInInv(Blackboard* blackboardPtr, eItemType type);
bool HpUnderThreshold(Blackboard* blackboardPtr, float threshold); bool HpUnderThreshold(Blackboard* blackboardPtr, float threshold);
bool CheckMinNeededEnergy(Blackboard* blackboardPtr); bool CheckMinNeededEnergy(Blackboard* blackboardPtr);
@@ -57,5 +69,6 @@ namespace BT_Condition
bool SeeHouse(Blackboard* blackboardPtr); bool SeeHouse(Blackboard* blackboardPtr);
bool NewHouse(Blackboard* blackboardPtr); bool NewHouse(Blackboard* blackboardPtr);
bool ReExploreHouse(Blackboard* blackboardPtr); bool ReExploreHouse(Blackboard* blackboardPtr);
} }

View File

@@ -4,34 +4,80 @@
#include "Behaviour.h" #include "Behaviour.h"
#include "BehaviourTree.h" #include "BehaviourTree.h"
using namespace std::placeholders;
namespace BigThink namespace BigThink
{ {
constexpr float HpThreshold{ 8.f }; // TODO: Make this a parameter BT::Sequence* ZombieHandling() {
constexpr float minShotgunAngleDiff{ .2f };
constexpr float minPistolAngleDiff{ .1f };
constexpr float maxShotgunShootRange{ 8.f };
constexpr float maxPistolShootRange{ 15.f };
const std::string ShotgunTimer{ "Shotgun" };
constexpr bool ShotgunDoOnce{ true };
const std::string PistolTimer{ "Pistol" };
constexpr bool PistolDoOnce{ true };
return
new BT::Sequence({
new BT::Conditional(BT_Condition::SeeZombie),
new BT::Sequence({
new BT::Action(BT_Action::AvoidingZombie),
new BT::Conditional(BT_Condition::HasWeapon),
new BT::Action(BT_Action::SetZombieTarget),
new BT::Sequence({
new BT::Action(BT_Action::RotateToZombie),
new BT::Selector({
new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::SHOTGUN)),
new BT::Conditional(std::bind(BT_Condition::InRange, _1, maxShotgunShootRange)),
new BT::Action(std::bind(BT_Action::ReadyToShoot, _1, minShotgunAngleDiff)),
new BT::Conditional(std::bind(BT_Condition::CheckTimer, _1, ShotgunTimer, ShotgunDoOnce)),
new BT::Action(std::bind(BT_Action::Shoot, _1, eItemType::SHOTGUN)),
new BT::Action(std::bind(BT_Action::SetTimer, _1, ShotgunTimer, ShotgunDoOnce))
}),
new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::PISTOL)),
new BT::Conditional(std::bind(BT_Condition::InRange, _1, maxPistolShootRange)),
new BT::Action(std::bind(BT_Action::ReadyToShoot, _1, minPistolAngleDiff)),
new BT::Conditional(std::bind(BT_Condition::CheckTimer, _1, PistolTimer, PistolDoOnce)),
new BT::Action(std::bind(BT_Action::Shoot, _1, eItemType::PISTOL)),
new BT::Action(std::bind(BT_Action::SetTimer, _1, PistolTimer, PistolDoOnce))
})
})
})
})
});
}
BT::Sequence* PurgeZoneHandling() { BT::Sequence* PurgeZoneHandling() {
constexpr int searchDegree{ 45 }; constexpr int searchDegree{ 5 };
return return
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(BT_Condition::SeePurgeZone), new BT::Conditional(BT_Condition::SeePurgeZone),
new BT::Action(std::bind(BT_Action::FindClosestEdge, std::placeholders::_1, searchDegree)), new BT::Action(std::bind(BT_Action::FindClosestEdge, _1, searchDegree)),
new BT::Action(BT_Action::GoToTarget) new BT::Action(BT_Action::GoToTarget)
}); });
} }
BT::Selector* ItemHandling() { BT::Selector* ItemHandling() {
constexpr float HpThreshold{ 0.f };
return return
new BT::Selector({ new BT::Selector({
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, std::placeholders::_1, eItemType::MEDKIT)), new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::MEDKIT)),
new BT::Conditional(std::bind(BT_Condition::HpUnderThreshold, std::placeholders::_1, HpThreshold)), new BT::Conditional(std::bind(BT_Condition::HpUnderThreshold, _1, HpThreshold)),
new BT::Action(std::bind(BT_Action::UseItem, std::placeholders::_1, eItemType::MEDKIT)) new BT::Action(std::bind(BT_Action::UseItem, _1, eItemType::MEDKIT))
}), }),
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, std::placeholders::_1, eItemType::FOOD)), new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::FOOD)),
new BT::Conditional(BT_Condition::CheckMinNeededEnergy), new BT::Conditional(BT_Condition::CheckMinNeededEnergy),
new BT::Action(std::bind(BT_Action::UseItem, std::placeholders::_1, eItemType::FOOD)) new BT::Action(std::bind(BT_Action::UseItem, _1, eItemType::FOOD))
}) })
}); });
} }
BT::PartialSequence* PickUpHandling() { BT::PartialSequence* PickUpHandling() {
@@ -43,7 +89,7 @@ namespace BigThink
new BT::Action(BT_Action::GoToTarget), new BT::Action(BT_Action::GoToTarget),
new BT::Selector({ new BT::Selector({
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, std::placeholders::_1, eItemType::GARBAGE)), new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, _1, eItemType::GARBAGE)),
new BT::Action(BT_Action::DestroyItemOnFloor) new BT::Action(BT_Action::DestroyItemOnFloor)
}), }),
new BT::Sequence({ new BT::Sequence({
@@ -58,19 +104,19 @@ namespace BigThink
new BT::Conditional(BT_Condition::InvIsFull), new BT::Conditional(BT_Condition::InvIsFull),
new BT::Selector({ new BT::Selector({
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, std::placeholders::_1, eItemType::FOOD)), new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem,_1, eItemType::FOOD)),
new BT::Action(BT_Action::CheckItem) new BT::Action(BT_Action::CheckItem)
}), }),
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, std::placeholders::_1, eItemType::MEDKIT)), new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, _1, eItemType::MEDKIT)),
new BT::Action(BT_Action::CheckItem) new BT::Action(BT_Action::CheckItem)
}), }),
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, std::placeholders::_1, eItemType::SHOTGUN)), new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, _1, eItemType::SHOTGUN)),
new BT::Action(BT_Action::CheckItem) new BT::Action(BT_Action::CheckItem)
}), }),
new BT::Sequence({ new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, std::placeholders::_1, eItemType::PISTOL)), new BT::Conditional(std::bind(BT_Condition::IsTypeOfItem, _1, eItemType::PISTOL)),
new BT::Action(BT_Action::CheckItem) new BT::Action(BT_Action::CheckItem)
}) })
}) })
@@ -80,9 +126,10 @@ namespace BigThink
} }
BT::Selector* HouseHandling() { BT::Selector* HouseHandling() {
constexpr float maxTravelDistance{ 100.f }; constexpr float maxTravelDistance{ 400.f };
constexpr int searchRadius{ 300 }; constexpr int searchRadius{ 500 };
constexpr int searchDegree{ 45 }; //TODO constexpr int randomRadius{ 50 };
constexpr int searchDegree{ 5 };
constexpr float InsideOffset{ 5.f }; constexpr float InsideOffset{ 5.f };
const std::string BeforeLeavingTimer{ "BeforeLeaving" }; const std::string BeforeLeavingTimer{ "BeforeLeaving" };
@@ -90,60 +137,70 @@ namespace BigThink
return return
new BT::Selector({ new BT::Selector({
new BT::Sequence({
new BT::Conditional(BT_Condition::SeeHouse),
new BT::Action(BT_Action::CheckHouses)
}),
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Conditional(BT_Condition::InsideTargetHouse), new BT::Conditional(BT_Condition::InsideTargetHouse),
new BT::Action(BT_Action::SetExpireDate), new BT::Action(BT_Action::SetExpireDate),
new BT::Action(std::bind(BT_Action::SetTimer, std::placeholders::_1, BeforeLeavingTimer, BeforeLeavingDoOnce)), new BT::Action(std::bind(BT_Action::SetTimer, _1, BeforeLeavingTimer, BeforeLeavingDoOnce)),
new BT::Selector({ new BT::Selector({
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Conditional(std::bind(BT_Condition::CheckTimer, std::placeholders::_1, BeforeLeavingTimer, BeforeLeavingDoOnce)), new BT::Conditional(std::bind(BT_Condition::CheckTimer, _1, BeforeLeavingTimer, BeforeLeavingDoOnce)),
new BT::Selector({ new BT::Selector({
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Conditional(BT_Condition::NewHouse), new BT::Conditional(BT_Condition::NewHouse),
new BT::Action(std::bind(BT_Action::GetHouseAsTarget, std::placeholders::_1, maxTravelDistance)), new BT::Action(std::bind(BT_Action::GetHouseAsTarget, _1, maxTravelDistance)),
new BT::Action(BT_Action::EnableSpin), new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget), new BT::Action(BT_Action::GoToTarget),
}), }),
new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::TryFindHouse, _1, searchRadius, searchDegree)),
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget)
}),
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Conditional(BT_Condition::ReExploreHouse), new BT::Conditional(BT_Condition::ReExploreHouse),
new BT::Action(std::bind(BT_Action::GetHouseAsTarget, std::placeholders::_1, maxTravelDistance)), new BT::Action(std::bind(BT_Action::GetHouseAsTarget, _1, maxTravelDistance)),
new BT::Action(BT_Action::EnableSpin), new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget), new BT::Action(BT_Action::GoToTarget),
}), }),
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::TryFindHouse, std::placeholders::_1, searchRadius, searchDegree)), new BT::Action(std::bind(BT_Action::FindRandomLocation, _1, randomRadius)),
new BT::Action(BT_Action::EnableSpin), new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget) new BT::Action(BT_Action::GoToTarget)
}) })
}), }),
}), }),
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::GetInsideTarget, std::placeholders::_1, InsideOffset)), new BT::Action(std::bind(BT_Action::GetInsideTarget, _1, InsideOffset)),
new BT::Action(BT_Action::EnableSpin), new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget) new BT::Action(BT_Action::GoToTarget)
}), }),
}) })
}), }),
new BT::Sequence({
new BT::Conditional(BT_Condition::SeeHouse),
new BT::Action(BT_Action::CheckHouses)
}),
new BT::Selector({ new BT::Selector({
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Conditional(BT_Condition::NewHouse), new BT::Conditional(BT_Condition::NewHouse),
new BT::Action(std::bind(BT_Action::GetHouseAsTarget, std::placeholders::_1, maxTravelDistance)), new BT::Action(std::bind(BT_Action::GetHouseAsTarget, _1, maxTravelDistance)),
new BT::Action(BT_Action::EnableSpin), new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget), new BT::Action(BT_Action::GoToTarget),
}), }),
new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::TryFindHouse, _1, searchRadius, searchDegree)),
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget)
}),
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Conditional(BT_Condition::ReExploreHouse), new BT::Conditional(BT_Condition::ReExploreHouse),
new BT::Action(std::bind(BT_Action::GetHouseAsTarget, std::placeholders::_1, maxTravelDistance)), new BT::Action(std::bind(BT_Action::GetHouseAsTarget, _1, maxTravelDistance)),
new BT::Action(BT_Action::EnableSpin), new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget), new BT::Action(BT_Action::GoToTarget),
}) })
}), }),
new BT::PartialSequence({ new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::TryFindHouse, std::placeholders::_1, searchRadius, searchDegree)), new BT::Action(std::bind(BT_Action::FindRandomLocation, _1, randomRadius)),
new BT::Action(BT_Action::EnableSpin), new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget) new BT::Action(BT_Action::GoToTarget)
}) })

View File

@@ -10,6 +10,7 @@ namespace BT
namespace BigThink namespace BigThink
{ {
BT::Sequence* ZombieHandling();
BT::Sequence* PurgeZoneHandling(); BT::Sequence* PurgeZoneHandling();
BT::Selector* ItemHandling(); BT::Selector* ItemHandling();
BT::PartialSequence* PickUpHandling(); BT::PartialSequence* PickUpHandling();

View File

@@ -29,6 +29,7 @@ void SurvivalAgentPlugin::Initialize(IBaseInterface* pInterface, PluginInfo& inf
Blackboard* blackboardPtr{ CreateBlackboard() }; Blackboard* blackboardPtr{ CreateBlackboard() };
m_BehaviourTree = new BT::BehaviorTree(blackboardPtr, m_BehaviourTree = new BT::BehaviorTree(blackboardPtr,
new BT::Selector({ new BT::Selector({
BigThink::ZombieHandling(),
BigThink::PurgeZoneHandling(), BigThink::PurgeZoneHandling(),
BigThink::ItemHandling(), BigThink::ItemHandling(),
BigThink::PickUpHandling(), BigThink::PickUpHandling(),
@@ -51,17 +52,24 @@ Blackboard* SurvivalAgentPlugin::CreateBlackboard() {
blackboardPtr->AddData("MaxFailSafe", 2.f); blackboardPtr->AddData("MaxFailSafe", 2.f);
blackboardPtr->AddData("FailSafeDoOnce", false); blackboardPtr->AddData("FailSafeDoOnce", false);
blackboardPtr->AddData("TargetZombie", EnemyInfo{});
blackboardPtr->AddData("angleDiff", float{});
blackboardPtr->AddData("TimerShotgun", std::chrono::steady_clock::time_point{});
blackboardPtr->AddData("TimerShotgunDoOnce", false);
blackboardPtr->AddData("MaxTimeShotgun", 1.f);
blackboardPtr->AddData("TimerPistol", std::chrono::steady_clock::time_point{});
blackboardPtr->AddData("TimerPistolDoOnce", false);
blackboardPtr->AddData("MaxTimePistol", 1.f);
blackboardPtr->AddData("TargetItem", ItemInfo{}); blackboardPtr->AddData("TargetItem", ItemInfo{});
blackboardPtr->AddData("NextFreeSlot", 0); blackboardPtr->AddData("NextFreeSlot", 0);
blackboardPtr->AddData("TargetHouse", HouseInfo{}); blackboardPtr->AddData("TargetHouse", HouseInfo{});
blackboardPtr->AddData("TimerBeforeLeaving", std::chrono::steady_clock::time_point{}); blackboardPtr->AddData("TimerBeforeLeaving", std::chrono::steady_clock::time_point{});
blackboardPtr->AddData("TimerBeforeLeavingDoOnce", false); blackboardPtr->AddData("TimerBeforeLeavingDoOnce", false);
blackboardPtr->AddData("MaxTimeBeforeLeaving", 5.f); blackboardPtr->AddData("MaxTimeBeforeLeaving", 3.f);
return blackboardPtr; return blackboardPtr;
} }
void SurvivalAgentPlugin::UpdateBlackboard(const SteeringPlugin_Output& steering) { void SurvivalAgentPlugin::UpdateBlackboard(const SteeringPlugin_Output& steering) {
@@ -105,7 +113,7 @@ void SurvivalAgentPlugin::InitGameDebugParams(GameDebugParams& params)
params.SpawnPurgeZonesOnMiddleClick = true; params.SpawnPurgeZonesOnMiddleClick = true;
params.PrintDebugMessages = true; params.PrintDebugMessages = true;
params.ShowDebugItemNames = true; params.ShowDebugItemNames = true;
params.Seed = 0; //-1 = don't set seed. Any other number = fixed seed //TIP: use Seed = int(time(nullptr)) for pure randomness params.Seed = -1; //-1 = don't set seed. Any other number = fixed seed //TIP: use Seed = int(time(nullptr)) for pure randomness
} }
void SurvivalAgentPlugin::Update_Debug(float dt) void SurvivalAgentPlugin::Update_Debug(float dt)
@@ -176,8 +184,8 @@ void SurvivalAgentPlugin::Update_Debug(float dt)
//This function calculates the new SteeringOutput, called once per frame //This function calculates the new SteeringOutput, called once per frame
SteeringPlugin_Output SurvivalAgentPlugin::UpdateSteering(float dt) SteeringPlugin_Output SurvivalAgentPlugin::UpdateSteering(float dt)
{ {
auto steering = SteeringPlugin_Output(); auto steering = SteeringPlugin_Output(Elite::Vector2{}, m_pInterface->Agent_GetInfo().MaxAngularSpeed, true, false);
bool spin{}; bool spin{ false };
UpdateBlackboard(steering); UpdateBlackboard(steering);
@@ -188,7 +196,6 @@ SteeringPlugin_Output SurvivalAgentPlugin::UpdateSteering(float dt)
if (spin) { if (spin) {
steering.AutoOrient = false; steering.AutoOrient = false;
steering.AngularVelocity = 3.14f;
} }
if (m_GrabItem) { if (m_GrabItem) {
@@ -203,6 +210,7 @@ SteeringPlugin_Output SurvivalAgentPlugin::UpdateSteering(float dt)
return steering; return steering;
} }
//This function should only be used for rendering debug elements //This function should only be used for rendering debug elements
@@ -210,6 +218,13 @@ void SurvivalAgentPlugin::Render(float dt) const
{ {
//This Render function should only contain calls to Interface->Draw_... functions //This Render function should only contain calls to Interface->Draw_... functions
m_pInterface->Draw_SolidCircle(m_Target, .7f, { 0,0 }, { 1, 0, 0 }); m_pInterface->Draw_SolidCircle(m_Target, .7f, { 0,0 }, { 1, 0, 0 });
m_pInterface->Draw_Circle(m_pInterface->Agent_GetInfo().Position, 500.f, { 1.f, 0.f, 0 });
m_pInterface->Draw_Circle(m_pInterface->Agent_GetInfo().Position, 400.f, { 1.f, 1.f, 0 });
m_pInterface->Draw_Circle(m_pInterface->Agent_GetInfo().Position, 50.f, { 1.f, 1.f, 1.f });
m_pInterface->Draw_Circle(m_pInterface->Agent_GetInfo().Position, 15.f, { 0.f, 1.f, 1.f });
m_pInterface->Draw_Circle(m_pInterface->Agent_GetInfo().Position, 8.f, { 0.f, 1.f, 1.f });
} }