mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-21 07:59:25 +02:00
# Pull Request
- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )
Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---
## Complexity & Impact
- Does this change add new decision branches?
- [x] No
- [ ] Yes (**explain below**)
- Does this change increase per-bot or per-tick processing?
- [x] No
- [ ] Yes (**describe and justify impact**)
- Could this logic scale poorly under load?
- [x] No
- [ ] Yes (**explain why**)
---
## Defaults & Configuration
- Does this change modify default bot behavior?
- [x] No
- [ ] Yes (**explain why**)
---
## AI Assistance
- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
- [x] No
- [ ] Yes (**explain below**)
---
## Final Checklist
- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed
---
## Notes for Reviewers
Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.
---------
Co-authored-by: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
95 lines
2.9 KiB
C++
95 lines
2.9 KiB
C++
/*
|
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
|
|
* and/or modify it under version 3 of the License, or (at your option), any later version.
|
|
*/
|
|
|
|
#ifndef PLAYERBOT_QUEUE_H
|
|
#define PLAYERBOT_QUEUE_H
|
|
|
|
#include "Action.h"
|
|
#include "Common.h"
|
|
|
|
/**
|
|
* @class Queue
|
|
* @brief Manages a priority queue of actions for the playerbot system
|
|
*
|
|
* This queue maintains a list of ActionBasket objects, each containing an action
|
|
* and its relevance score. Actions with higher relevance scores are prioritized.
|
|
*/
|
|
class Queue
|
|
{
|
|
public:
|
|
Queue() = default;
|
|
~Queue() = default;
|
|
|
|
/**
|
|
* @brief Adds an action to the queue or updates existing action's relevance
|
|
* @param action Pointer to the ActionBasket to be added
|
|
*
|
|
* If an action with the same name exists, updates its relevance if the new
|
|
* relevance is higher, then deletes the new action. Otherwise, adds the new
|
|
* action to the queue.
|
|
*/
|
|
void Push(ActionBasket* action);
|
|
|
|
/**
|
|
* @brief Removes and returns the action with highest relevance
|
|
* @return Pointer to the highest relevance ActionNode, or nullptr if queue is empty
|
|
*
|
|
* Ownership of the returned ActionNode is transferred to the caller.
|
|
* The associated ActionBasket is deleted.
|
|
*/
|
|
ActionNode* Pop();
|
|
|
|
/**
|
|
* @brief Returns the action with highest relevance without removing it
|
|
* @return Pointer to the ActionBasket with highest relevance, or nullptr if queue is empty
|
|
*/
|
|
ActionBasket* Peek();
|
|
|
|
/**
|
|
* @brief Returns the current size of the queue
|
|
* @return Number of actions in the queue
|
|
*/
|
|
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
|
|
*/
|
|
void updateExistingBasket(ActionBasket* existing, ActionBasket* newBasket);
|
|
|
|
/**
|
|
* @brief Finds the basket with the highest relevance score
|
|
* @return Pointer to the highest relevance basket, or nullptr if queue is empty
|
|
*/
|
|
ActionBasket* findHighestRelevanceBasket() const;
|
|
|
|
/**
|
|
* @brief Extracts action from basket and handles basket cleanup
|
|
*/
|
|
ActionNode* extractAndDeleteBasket(ActionBasket* basket);
|
|
|
|
/**
|
|
* @brief Collects all expired baskets into the provided list
|
|
*/
|
|
void collectExpiredBaskets(std::list<ActionBasket*>& expiredBaskets);
|
|
|
|
/**
|
|
* @brief Removes and deletes all baskets in the provided list
|
|
*/
|
|
void removeAndDeleteBaskets(std::list<ActionBasket*>& basketsToRemove);
|
|
|
|
std::list<ActionBasket*> actions; /**< Container for action baskets */
|
|
};
|
|
|
|
#endif
|