This commit is contained in:
Bram verhulst
2025-06-02 21:29:29 +02:00
parent 1104b12ba8
commit f9a11385fe
17 changed files with 3338 additions and 274 deletions

View File

@@ -9,7 +9,7 @@ using namespace std::placeholders;
namespace BigThink
{
BT::Selector* ItemHandling() {
constexpr float HpThreshold{ 0.f };
constexpr float HpThreshold{ 2.f };
return
new BT::Selector({
@@ -131,21 +131,29 @@ namespace BigThink
constexpr int randomRadius{ 50 };
constexpr int searchDegree{ 5 };
constexpr float InsideOffset{ 5.f };
constexpr float gridCellSize{ 50.f };
const std::string BeforeLeavingTimer{ "BeforeLeaving" };
constexpr bool BeforeLeavingDoOnce{ false };
const std::string NoHouseTimer{ "NoHouse" };
constexpr float noHouseTimeout = 5.0f; // Time in seconds before giving up and going random
constexpr float noHouseTimeout = 5.0f;
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(std::bind(BT_Action::SetTimer, _1, NoHouseTimer, NoHouseDoOnce)) // Reset timer when we see a house
}),
const std::string HouseExploreTimer{ "HouseExplore" };
constexpr float houseExploreTimeout = 2.0f;
constexpr bool HouseExploreDoOnce{ false };
return new BT::Selector({
// [1] House visibility update
new BT::Sequence({
new BT::Conditional(BT_Condition::SeeHouse),
new BT::Action(BT_Action::CheckHouses),
//new BT::Action(BT_Grid::UpdateExplorationGrid),
new BT::Action(std::bind(BT_Action::SetTimer, _1, NoHouseTimer, NoHouseDoOnce))
}),
// [2] Inside house logic
new BT::PartialSequence({
new BT::Conditional(BT_Condition::InsideTargetHouse),
new BT::Action(BT_Action::SetExpireDate),
@@ -161,21 +169,16 @@ 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)
}),
/*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::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),
@@ -190,6 +193,8 @@ namespace BigThink
}),
})
}),
// [3] Outside house behavior
new BT::Selector({
new BT::PartialSequence({
new BT::Conditional(BT_Condition::NewHouse),
@@ -198,24 +203,48 @@ 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(BT_Grid::FindUnexploredCell),
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::Conditional(std::bind(BT_Condition::CheckTimer, _1, NoHouseTimer, NoHouseDoOnce)),
new BT::Action(std::bind(BT_Action::SetTimer, _1, NoHouseTimer, NoHouseDoOnce)),
new BT::Selector({
new BT::PartialSequence({
new BT::Action(BT_Grid::FindUnexploredCell),
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 * 2)),
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),
})
}),
});
}
BT::Selector* HandleBug() {
const std::string StuckTimer{ "StuckTimer" };
constexpr float stuckTimeout = 3.0f; // Time in seconds before considering stuck
constexpr bool StuckDoOnce{ false };
constexpr float unstuckRange = 10.0f; // Range to pick a random target when stuck
return
new BT::Selector({
new BT::Sequence({
new BT::Conditional(std::bind(BT_Condition::CheckMovement, _1, stuckTimeout)),
new BT::Conditional(std::bind(BT_Condition::CheckTimer, _1, StuckTimer, StuckDoOnce)),
new BT::Action(std::bind(BT_Action::SetTimer, _1, StuckTimer, StuckDoOnce)),
new BT::Action(std::bind(BT_Action::FindRandomLocation, _1, unstuckRange)),
new BT::Action(BT_Action::EnableSpin),
new BT::Action(BT_Action::GoToTarget)
})
});
}
}