23 typedef std::vector<Entry> Entries;
24 typedef Entries::iterator EntriesIter;
26 mutable Entries _entries;
30 float _minAggro = 0.0f;
31 float _reduceRatioSecond = 0.0f;
32 float _reduceValueSecond = 0.0f;
33 ReductionType _reduceType = DISABLED;
37 const CharacterId& _id;
43 inline bool operator()(
const Entry &n1) {
44 return n1.getCharacterId() == _id;
48 static bool EntrySorter(
const Entry& a,
const Entry& b) {
49 if (a.getAggro() > b.getAggro()) {
52 if (::fabs(a.getAggro() - b.getAggro()) < 0.0000001f) {
53 return a.getCharacterId() < b.getCharacterId();
63 EntriesIter::difference_type
remove = 0;
64 for (EntriesIter i = _entries.begin(); i != _entries.end(); ++i) {
65 const float aggroValue = i->getAggro();
66 if (aggroValue > 0.0f) {
77 const int size =
static_cast<int>(_entries.size());
83 EntriesIter i = _entries.begin();
84 std::advance(i,
remove);
85 _entries.erase(_entries.begin(), i);
88 inline void sort()
const {
92 std::sort(_entries.begin(), _entries.end(), EntrySorter);
96 explicit AggroMgr(std::size_t expectedEntrySize = 0u) :
98 if (expectedEntrySize > 0) {
99 _entries.reserve(expectedEntrySize);
103 virtual ~AggroMgr() {
106 inline void setReduceByRatio(
float reduceRatioSecond,
float minAggro) {
108 _reduceValueSecond = 0.0f;
109 _reduceRatioSecond = reduceRatioSecond;
110 _minAggro = minAggro;
113 inline void setReduceByValue(
float reduceValueSecond) {
115 _reduceValueSecond = reduceValueSecond;
116 _reduceRatioSecond = 0.0f;
120 inline void resetReduceValue() {
121 _reduceType = DISABLED;
122 _reduceValueSecond = 0.0f;
123 _reduceRatioSecond = 0.0f;
132 for (EntriesIter i = _entries.begin(); i != _entries.end(); ++i) {
133 _dirty |= i->reduceByTime(deltaMillis);
150 EntriesIter i = std::find_if(_entries.begin(), _entries.end(), p);
151 if (i == _entries.end()) {
152 Entry newEntry(
id, amount);
153 switch (_reduceType) {
155 newEntry.setReduceByRatio(_reduceRatioSecond, _minAggro);
158 newEntry.setReduceByValue(_reduceValueSecond);
163 _entries.push_back(newEntry);
165 return &_entries.back();
186 if (_entries.empty()) {
192 return &_entries.back();
Manages the aggro values for one AI instance. There are several ways to degrade the aggro values...
Definition: AggroMgr.h:21
Definition: AggroMgr.h:35
const Entries & getEntries() const
Definition: AggroMgr.h:176
EntryPtr addAggro(CharacterId id, float amount)
will increase the aggro
Definition: AggroMgr.h:148
EntryPtr getHighestEntry() const
Get the entry with the highest aggro value.
Definition: AggroMgr.h:185
One entry for the AggroMgr.
Definition: Entry.h:17
void cleanupList()
Remove the entries from the list that have no aggro left. This list is ordered, so we will only remov...
Definition: AggroMgr.h:62
void update(int64_t deltaMillis)
this will update the aggro list according to the reduction type of an entry.
Definition: AggroMgr.h:131