diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index b7b70dd4..35b75442 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -305,6 +305,9 @@ AiPlayerbot.DisableMoveSplinePath = 0 # default: 3 AiPlayerbot.MaxMovementSearchTime = 3 +# Action expiration time +AiPlayerbot.ExpireActionTime = 5000 + # Max dispel auras duration AiPlayerbot.DispelAuraDuration = 700 diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index a7568a85..0ff76fb6 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -71,6 +71,7 @@ bool PlayerbotAIConfig::Initialize() maxWaitForMove = sConfigMgr->GetOption("AiPlayerbot.MaxWaitForMove", 5000); disableMoveSplinePath = sConfigMgr->GetOption("AiPlayerbot.DisableMoveSplinePath", 0); maxMovementSearchTime = sConfigMgr->GetOption("AiPlayerbot.MaxMovementSearchTime", 3); + expireActionTime = sConfigMgr->GetOption("AiPlayerbot.ExpireActionTime", 5000); dispelAuraDuration = sConfigMgr->GetOption("AiPlayerbot.DispelAuraDuration", 7000); reactDelay = sConfigMgr->GetOption("AiPlayerbot.ReactDelay", 100); dynamicReactDelay = sConfigMgr->GetOption("AiPlayerbot.DynamicReactDelay", true); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index ce2a0cb6..527fb6cd 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -57,7 +57,7 @@ public: bool enabled; bool allowAccountBots, allowGuildBots; bool randomBotGuildNearby, randomBotInvitePlayer, inviteChat; - uint32 globalCoolDown, reactDelay, maxWaitForMove, disableMoveSplinePath, maxMovementSearchTime, + uint32 globalCoolDown, reactDelay, maxWaitForMove, disableMoveSplinePath, maxMovementSearchTime, expireActionTime, dispelAuraDuration, passiveDelay, repeatDelay, errorDelay, rpgDelay, sitDelay, returnDelay, lootDelay; bool dynamicReactDelay; float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance, fleeDistance, diff --git a/src/strategy/Engine.cpp b/src/strategy/Engine.cpp index f15293b8..39524596 100644 --- a/src/strategy/Engine.cpp +++ b/src/strategy/Engine.cpp @@ -239,13 +239,9 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal) } if (!actionExecuted) - LogAction("No actions executed"); - - ActionNode* action = nullptr; - while ((action = queue.Pop()) != nullptr) - { - delete action; - } + LogAction("no actions executed"); + + queue.RemoveExpired(); return actionExecuted; } diff --git a/src/strategy/Queue.cpp b/src/strategy/Queue.cpp index f1273294..b2c6e88d 100644 --- a/src/strategy/Queue.cpp +++ b/src/strategy/Queue.cpp @@ -48,6 +48,18 @@ uint32 Queue::Size() return actions.size(); } +void Queue::RemoveExpired() +{ + if (!sPlayerbotAIConfig->expireActionTime) + { + return; + } + + std::list expiredBaskets; + collectExpiredBaskets(expiredBaskets); + removeAndDeleteBaskets(expiredBaskets); +} + // Private helper methods void Queue::updateExistingBasket(ActionBasket* existing, ActionBasket* newBasket) { @@ -93,3 +105,30 @@ ActionNode* Queue::extractAndDeleteBasket(ActionBasket* basket) delete basket; return action; } + +void Queue::collectExpiredBaskets(std::list& expiredBaskets) +{ + uint32 expiryTime = sPlayerbotAIConfig->expireActionTime; + for (ActionBasket* basket : actions) + { + if (basket->isExpired(expiryTime)) + { + expiredBaskets.push_back(basket); + } + } +} + +void Queue::removeAndDeleteBaskets(std::list& basketsToRemove) +{ + for (ActionBasket* basket : basketsToRemove) + { + actions.remove(basket); + + if (ActionNode* action = basket->getAction()) + { + delete action; + } + + delete basket; + } +} diff --git a/src/strategy/Queue.h b/src/strategy/Queue.h index 8da0aa6f..23776655 100644 --- a/src/strategy/Queue.h +++ b/src/strategy/Queue.h @@ -53,6 +53,14 @@ public: */ uint32 Size(); + /** + * @brief Removes and deletes expired actions from the queue + * + * Uses sPlayerbotAIConfig->expireActionTime to determine if actions have expired. + * Both the ActionNode and ActionBasket are deleted for expired actions. + */ + void RemoveExpired(); + private: /** * @brief Updates existing basket with new relevance and cleans up new basket @@ -70,6 +78,11 @@ private: */ ActionNode* extractAndDeleteBasket(ActionBasket* basket); + /** + * @brief Collects all expired baskets into the provided list + */ + void collectExpiredBaskets(std::list& expiredBaskets); + /** * @brief Removes and deletes all baskets in the provided list */