fix some more glitchy stuff

This commit is contained in:
Bram verhulst
2025-06-01 23:04:37 +02:00
parent 1d2ca4f9ca
commit 1104b12ba8
14 changed files with 1529 additions and 305 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -869,8 +869,8 @@ Size=240,520
Collapsed=0
[WORLD INFO [33 FPS]]
Pos=651,10
Size=240,431
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [315 FPS]]
@@ -2123,3 +2123,68 @@ Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [735 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [30 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [28 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [26 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [24 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [777 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [31 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [776 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [774 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [710 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [769 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [763 FPS]]
Pos=710,10
Size=240,520
Collapsed=0
[WORLD INFO [748 FPS]]
Pos=710,10
Size=240,520
Collapsed=0

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,6 @@
# ./lib CMakeLists.txt
set(EXAM_LIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/GPP_PluginBase_d.lib" PARENT_SCOPE)
#set(EXAM_LIB_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/GPP_PluginBase_d.lib" PARENT_SCOPE)
set(EXAM_LIB_DEBUG
"$<IF:$<CONFIG:Debug>,${CMAKE_CURRENT_SOURCE_DIR}/GPP_PluginBase_d.lib,${CMAKE_CURRENT_SOURCE_DIR}/GPP_PluginBase.lib>"
PARENT_SCOPE)

View File

@@ -6,6 +6,8 @@
#define TO_RAD(i) i * (M_PI / 180)
#define PRINT_FUNCTION_NAME() std::cout << __func__ << std::endl
static int randNumRange(int minRange, int maxRange) {
std::random_device rd;
std::mt19937 seed(rd());
@@ -17,6 +19,7 @@ static int randNumRange(int minRange, int maxRange) {
namespace BT_Action
{
BT::State SetTimer(Blackboard* blackboardPtr, const std::string& timerName, bool doOnce) {
PRINT_FUNCTION_NAME();
bool didOnce{};
blackboardPtr->GetData("Timer" + timerName + "DoOnce", didOnce);
@@ -32,18 +35,21 @@ namespace BT_Action
}
BT::State UnlockTimer(Blackboard* blackboardPtr, const std::string& timerName) {
PRINT_FUNCTION_NAME();
blackboardPtr->ChangeData("TimerLock" + timerName, false);
return BT::State::Success;
}
BT::State LockTimer(Blackboard* blackboardPtr, const std::string& timerName) {
PRINT_FUNCTION_NAME();
blackboardPtr->ChangeData("TimerLock" + timerName, true);
return BT::State::Success;
}
BT::State GoToTarget(Blackboard* blackboardPtr) {
//PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Elite::Vector2 target{};
SteeringPlugin_Output steering{};
@@ -71,7 +77,7 @@ namespace BT_Action
steering.LinearVelocity = nextTargetPos - agentInfo.Position;
steering.LinearVelocity.Normalize();
steering.LinearVelocity *= agentInfo.MaxLinearSpeed * 100;
steering.LinearVelocity *= agentInfo.MaxLinearSpeed;
const std::chrono::steady_clock::time_point currentTime{ std::chrono::steady_clock::now() };
const std::chrono::duration<float> elapsedSec{ currentTime - timer };
@@ -81,7 +87,7 @@ namespace BT_Action
return BT::State::Success;
}
if (Distance(target, agentInfo.Position) < 2.f) {
if (Distance(target, agentInfo.Position) < 3.f) {
blackboardPtr->ChangeData("FailSafeDoOnce", false);
return BT::State::Success;
@@ -93,6 +99,7 @@ namespace BT_Action
}
BT::State EnableSpin(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
SteeringPlugin_Output steering{};
@@ -109,6 +116,7 @@ namespace BT_Action
}
BT::State DisableSpin(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
blackboardPtr->ChangeData("Spin", false);
return BT::State::Success;
@@ -116,6 +124,7 @@ namespace BT_Action
BT::State FindClosestEdge(Blackboard* blackboardPtr, int degree) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
@@ -150,6 +159,7 @@ namespace BT_Action
}
BT::State SetZombieTarget(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
@@ -176,6 +186,7 @@ namespace BT_Action
}
BT::State AvoidingZombie(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
SteeringPlugin_Output steering{};
@@ -201,6 +212,7 @@ namespace BT_Action
}
BT::State RotateToZombie(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
EnemyInfo zombieInfo{};
SteeringPlugin_Output steering{};
@@ -222,6 +234,7 @@ namespace BT_Action
}
BT::State ReadyToShoot(Blackboard* blackboardPtr, float minAngleDiff) {
PRINT_FUNCTION_NAME();
float angleDiff{};
blackboardPtr->GetData("angleDiff", angleDiff);
@@ -230,6 +243,7 @@ namespace BT_Action
}
BT::State Shoot(Blackboard* blackboardPtr, eItemType type) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
@@ -250,6 +264,7 @@ namespace BT_Action
}
BT::State SetItemAsTarget(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
@@ -277,6 +292,7 @@ namespace BT_Action
}
BT::State DestroyItemOnFloor(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
ItemInfo targetItem{};
@@ -290,6 +306,7 @@ namespace BT_Action
}
BT::State PickUpItem(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
ItemInfo targetItem{};
@@ -312,6 +329,7 @@ namespace BT_Action
}
BT::State SwapItem(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
ItemInfo targetItem{};
@@ -332,6 +350,7 @@ namespace BT_Action
}
BT::State CheckItem(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
ItemInfo targetItem{};
@@ -372,6 +391,7 @@ namespace BT_Action
}
BT::State UseItem(Blackboard* blackboardPtr, eItemType type) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
@@ -392,6 +412,7 @@ namespace BT_Action
}
BT::State TryFindHouse(Blackboard* blackboardPtr, float searchRadius, int degree) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
@@ -416,8 +437,9 @@ namespace BT_Action
const Elite::Vector2 target = interfacePtr->NavMesh_GetClosestPathPoint(pointOnCircle);
if (target == Elite::Vector2(400, 400)) {
std::cout << pointOnCircle << std::endl;
const float worldDimensions{ interfacePtr->World_GetInfo().Dimensions.x / 2 };
if (std::abs(target.x) >= worldDimensions || std::abs(target.y) >= worldDimensions) {
continue;
}
if (pointOnCircle != target) {
@@ -444,12 +466,17 @@ namespace BT_Action
}
BT::State FindRandomLocation(Blackboard* blackboardPtr, float randomRadius) {
PRINT_FUNCTION_NAME();
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));
const float randomAngle = Elite::ToRadians(randNumRange(0.0f, 360.0f));
const Elite::Vector2 offset = Elite::Vector2{ cosf(randomAngle), sinf(randomAngle) } *randomRadius;
const Elite::Vector2 target = playerPos + offset;
blackboardPtr->ChangeData("Target", target);
@@ -457,6 +484,7 @@ namespace BT_Action
}
BT::State GetHouseAsTarget(Blackboard* blackboardPtr, float maxTravelDistance) {
PRINT_FUNCTION_NAME();
IExamInterface* interfacePtr{};
Thinker* thinkerPtr{};
@@ -476,6 +504,7 @@ namespace BT_Action
}
BT::State CheckHouses(Blackboard* blackboardPtr) {
//PRINT_FUNCTION_NAME();
Thinker* thinkerPtr{};
IExamInterface* interfacePtr{};
@@ -490,6 +519,7 @@ namespace BT_Action
}
BT::State SetExpireDate(Blackboard* blackboardPtr) {
PRINT_FUNCTION_NAME();
Thinker* thinkerPtr{};
HouseInfo targetHouse{};
@@ -502,6 +532,7 @@ namespace BT_Action
}
BT::State GetInsideTarget(Blackboard* blackboardPtr, float offset) {
PRINT_FUNCTION_NAME();
HouseInfo targetHouse{};
blackboardPtr->GetData("TargetHouse", targetHouse);
@@ -546,6 +577,28 @@ namespace BT_Condition
return false;
}
bool InPurgeZone(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
const Elite::Vector2 playerPos{ interfacePtr->Agent_GetInfo().Position };
for (const auto purgeZone : interfacePtr->GetPurgeZonesInFOV()) {
const Elite::Vector2 purgeCenter{ purgeZone.Center };
const float purgeRadius{ purgeZone.Radius };
const float x{ playerPos.x - purgeCenter.x };
const float y{ playerPos.y - purgeCenter.y };
const float result{ x * x + y * y - purgeRadius * purgeRadius };
if (result <= 0)
return true;
}
return false;
}
bool SeeZombie(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
@@ -569,13 +622,6 @@ namespace BT_Condition
return dist2 <= maxRange * maxRange;
}
bool SeePurgeZone(Blackboard* blackboardPtr) {
IExamInterface* interfacePtr{};
blackboardPtr->GetData("Interface", interfacePtr);
return interfacePtr->GetPurgeZonesInFOV().capacity() > 0;
}
bool ItemInInv(Blackboard* blackboardPtr, eItemType type) {
Thinker* thinkerPtr{};
blackboardPtr->GetData("Brain", thinkerPtr);
@@ -626,10 +672,6 @@ namespace BT_Condition
Thinker* thinkerPtr{};
blackboardPtr->GetData("Brain", thinkerPtr);
if (thinkerPtr->EmptyValue()) {
std::cout << "empty item\n";
}
return thinkerPtr->EmptyValue();
}
@@ -672,4 +714,5 @@ namespace BT_Condition
return thinkerPtr->HouseToReExplore();
}
}

View File

@@ -49,7 +49,7 @@ namespace BT_Condition
bool CheckTimerLock(Blackboard* blackboardPtr, const std::string& timerName);
bool CheckTimer(Blackboard* blackboardPtr, const std::string& timerName, bool doOnce);
bool SeePurgeZone(Blackboard* blackboardPtr);
bool InPurgeZone(Blackboard* blackboardPtr);
bool SeeZombie(Blackboard* blackboardPtr);
bool HasWeapon(Blackboard* blackboardPtr);

View File

@@ -8,6 +8,24 @@ using namespace std::placeholders;
namespace BigThink
{
BT::Selector* ItemHandling() {
constexpr float HpThreshold{ 0.f };
return
new BT::Selector({
new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::MEDKIT)),
new BT::Conditional(std::bind(BT_Condition::HpUnderThreshold, _1, HpThreshold)),
new BT::Action(std::bind(BT_Action::UseItem, _1, eItemType::MEDKIT))
}),
new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::FOOD)),
new BT::Conditional(BT_Condition::CheckMinNeededEnergy),
new BT::Action(std::bind(BT_Action::UseItem, _1, eItemType::FOOD))
})
});
}
BT::Sequence* ZombieHandling() {
constexpr float minShotgunAngleDiff{ .2f };
constexpr float minPistolAngleDiff{ .1f };
@@ -56,30 +74,12 @@ namespace BigThink
constexpr int searchDegree{ 5 };
return
new BT::Sequence({
new BT::Conditional(BT_Condition::SeePurgeZone),
new BT::Conditional(BT_Condition::InPurgeZone),
new BT::Action(std::bind(BT_Action::FindClosestEdge, _1, searchDegree)),
new BT::Action(BT_Action::GoToTarget)
});
}
BT::Selector* ItemHandling() {
constexpr float HpThreshold{ 0.f };
return
new BT::Selector({
new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::MEDKIT)),
new BT::Conditional(std::bind(BT_Condition::HpUnderThreshold, _1, HpThreshold)),
new BT::Action(std::bind(BT_Action::UseItem, _1, eItemType::MEDKIT))
}),
new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::ItemInInv, _1, eItemType::FOOD)),
new BT::Conditional(BT_Condition::CheckMinNeededEnergy),
new BT::Action(std::bind(BT_Action::UseItem, _1, eItemType::FOOD))
})
});
}
BT::PartialSequence* PickUpHandling() {
return
new BT::PartialSequence({
@@ -133,13 +133,18 @@ namespace BigThink
constexpr float InsideOffset{ 5.f };
const std::string BeforeLeavingTimer{ "BeforeLeaving" };
constexpr bool BeforeLeavingDoOnce{ true };
constexpr bool BeforeLeavingDoOnce{ false };
const std::string NoHouseTimer{ "NoHouse" };
constexpr float noHouseTimeout = 5.0f; // Time in seconds before giving up and going random
constexpr bool NoHouseDoOnce{ false };
return
new BT::Selector({
new BT::Sequence({
new BT::Conditional(BT_Condition::SeeHouse),
new BT::Action(BT_Action::CheckHouses)
new BT::Action(BT_Action::CheckHouses),
new BT::Action(std::bind(BT_Action::SetTimer, _1, NoHouseTimer, NoHouseDoOnce)) // Reset timer when we see a house
}),
new BT::PartialSequence({
new BT::Conditional(BT_Condition::InsideTargetHouse),
@@ -156,16 +161,21 @@ namespace BigThink
new BT::Action(BT_Action::GoToTarget),
}),
new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::TryFindHouse, _1, searchRadius, searchDegree)),
new BT::Action(std::bind(BT_Action::FindRandomLocation, _1, randomRadius)),
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget)
}),
new BT::PartialSequence({
/*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::Conditional(BT_Condition::ReExploreHouse),
new BT::Action(std::bind(BT_Action::GetHouseAsTarget, _1, maxTravelDistance)),
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget),
}),
}),*/
new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::FindRandomLocation, _1, randomRadius)),
new BT::Action(BT_Action::EnableSpin),
@@ -192,6 +202,13 @@ namespace BigThink
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget)
}),
new BT::PartialSequence({
new BT::Conditional(std::bind(BT_Condition::CheckTimer, _1, NoHouseTimer, NoHouseDoOnce)), // Check if we haven't seen a house in a while
new BT::Action(std::bind(BT_Action::SetTimer, _1, NoHouseTimer, NoHouseDoOnce)), // Reset the timer
new BT::Action(std::bind(BT_Action::FindRandomLocation, _1, randomRadius * 2)), // Go further when random walking
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget)
}),
new BT::PartialSequence({
new BT::Conditional(BT_Condition::ReExploreHouse),
new BT::Action(std::bind(BT_Action::GetHouseAsTarget, _1, maxTravelDistance)),
@@ -199,11 +216,6 @@ namespace BigThink
new BT::Action(BT_Action::GoToTarget),
})
}),
new BT::PartialSequence({
new BT::Action(std::bind(BT_Action::FindRandomLocation, _1, randomRadius)),
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget)
})
});
});
}
}

View File

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

View File

@@ -18,6 +18,12 @@ add_library(Exam_Plugin SHARED
target_link_libraries(Exam_Plugin PUBLIC ${EXAM_LIB_DEBUG})
target_include_directories(Exam_Plugin PUBLIC ${EXAM_INCLUDE_DIR})
# Explicit debug info generation flags for MSVC
target_compile_options(Exam_Plugin PRIVATE
$<$<CONFIG:Debug>:/Zi>)
target_link_options(Exam_Plugin PRIVATE
$<$<CONFIG:Debug>:/DEBUG>)
set_target_properties(Exam_Plugin PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/_DEMO_DEBUG"
LIBRARY_OUTPUT_DIRECTORY_DEBUG "${CMAKE_SOURCE_DIR}/_DEMO_DEBUG"
@@ -40,4 +46,4 @@ set_target_properties(GPP_EXAM_EXE PROPERTIES
)
# Ensure the DLL is built before the .exe is "built"
add_dependencies(GPP_EXAM_EXE Exam_Plugin)
add_dependencies(GPP_EXAM_EXE Exam_Plugin)

View File

@@ -29,9 +29,9 @@ void SurvivalAgentPlugin::Initialize(IBaseInterface* pInterface, PluginInfo& inf
Blackboard* blackboardPtr{ CreateBlackboard() };
m_BehaviourTree = new BT::BehaviorTree(blackboardPtr,
new BT::Selector({
BigThink::ItemHandling(),
BigThink::ZombieHandling(),
BigThink::PurgeZoneHandling(),
BigThink::ItemHandling(),
BigThink::PickUpHandling(),
BigThink::HouseHandling()
}));
@@ -69,6 +69,10 @@ Blackboard* SurvivalAgentPlugin::CreateBlackboard() {
blackboardPtr->AddData("TimerBeforeLeavingDoOnce", false);
blackboardPtr->AddData("MaxTimeBeforeLeaving", 3.f);
blackboardPtr->AddData("MaxTimeNoHouse", 5.f);
blackboardPtr->AddData("TimerNoHouse", std::chrono::steady_clock::time_point{});
blackboardPtr->AddData("TimerNoHouseDoOnce", false);
return blackboardPtr;
}
@@ -113,7 +117,7 @@ void SurvivalAgentPlugin::InitGameDebugParams(GameDebugParams& params)
params.SpawnPurgeZonesOnMiddleClick = true;
params.PrintDebugMessages = true;
params.ShowDebugItemNames = true;
params.Seed = -1; //-1 = don't set seed. Any other number = fixed seed //TIP: use Seed = int(time(nullptr)) for pure randomness
params.Seed = int(time(nullptr)); //-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)
@@ -194,6 +198,16 @@ SteeringPlugin_Output SurvivalAgentPlugin::UpdateSteering(float dt)
m_BehaviourTree->GetBlackboard()->GetData("Steering", steering);
m_BehaviourTree->GetBlackboard()->GetData("Spin", spin);
if (m_pInterface->Agent_GetInfo().Stamina >= 10 || m_Running) {
m_Running = true;
steering.RunMode = true;
}
if (m_pInterface->Agent_GetInfo().Stamina <= 0.1f) {
m_Running = false;
steering.RunMode = false;
}
if (spin) {
steering.AutoOrient = false;
}

View File

@@ -47,6 +47,8 @@ private:
void UpdateBlackboard(const SteeringPlugin_Output& steering);
BT::BehaviorTree* m_BehaviourTree = nullptr;
Thinker* m_Thinker = nullptr;
bool m_Running{};
};
//ENTRY

View File

@@ -3,19 +3,18 @@
#include <algorithm>
std::vector<Thinker::ItemMemory>::iterator Thinker::FindLeastValueItem(const eItemType& itemType) {
std::ranges::partition(m_ItemMemory,
[itemType](const ItemMemory& memory)->bool { return memory.ItemInfo.Type == itemType; });
auto minIt = m_ItemMemory.end();
const auto minItem =
std::ranges::min_element(m_ItemMemory,
[itemType](const ItemMemory& lhs, const ItemMemory& rhs)->bool {
if (lhs.ItemInfo.Type == itemType && rhs.ItemInfo.Type == itemType) {
return lhs.ItemInfo.Value < rhs.ItemInfo.Value;
}
return false;
});
for (auto it = m_ItemMemory.begin(); it != m_ItemMemory.end(); ++it) {
if (it->ItemInfo.Type != itemType)
continue;
return minItem;
if (minIt == m_ItemMemory.end() || it->ItemInfo.Value < minIt->ItemInfo.Value) {
minIt = it;
}
}
return minIt;
}
bool Thinker::IsInvNotFull() const {