diff options
author | Gacko <gacko28@gmx.de> | 2013-01-23 19:43:51 +0100 |
---|---|---|
committer | Gacko <gacko28@gmx.de> | 2013-01-30 18:39:34 +0100 |
commit | dbecf05e39204ff46621ce46bf5dd181e6450eeb (patch) | |
tree | c04cfe370e85cfdcb06d47aac71fee39d2c09f45 /src/server/game/AI/CreatureAIImpl.h | |
parent | 5a74336c5ed82b4691923947d7f75fcd72e1f1be (diff) |
Core: Logical fixes and improvements in EventMap
Diffstat (limited to 'src/server/game/AI/CreatureAIImpl.h')
-rw-r--r-- | src/server/game/AI/CreatureAIImpl.h | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/server/game/AI/CreatureAIImpl.h b/src/server/game/AI/CreatureAIImpl.h index 559240c4a3f..2b182901c8a 100644 --- a/src/server/game/AI/CreatureAIImpl.h +++ b/src/server/game/AI/CreatureAIImpl.h @@ -336,21 +336,35 @@ class EventMap // Sets event phase, must be in range 1 - 8 void SetPhase(uint32 phase) { - if (phase && phase < 8) - _phase = (1 << (phase + 24)); + if (phase && phase <= 8) + _phase = (1 << (phase + 23)); else if (!phase) _phase = 0; } + // Activates event phase, must be in range 1 - 8 + void AddPhase(uint32 phase) + { + if (phase && phase <= 8) + _phase |= (1 << (phase + 23)); + } + + // Deactivates event phase, must be in range 1 - 8 + void RemovePhase(uint32 phase) + { + if (phase && phase <= 8) + _phase &= ~(1 << (phase + 23)); + } + // Creates new event entry in map with given id, time, group if given (1 - 8) and phase if given (1 - 8) // 0 for group/phase means it belongs to no group or runs in all phases void ScheduleEvent(uint32 eventId, uint32 time, uint32 groupId = 0, uint32 phase = 0) { time += _time; if (groupId && groupId < 9) - eventId |= (1 << (groupId + 16)); + eventId |= (1 << (groupId + 15)); if (phase && phase < 8) - eventId |= (1 << (phase + 24)); + eventId |= (1 << (phase + 23)); StorageType::const_iterator itr = _eventMap.find(time); while (itr != _eventMap.end()) { @@ -443,8 +457,12 @@ class EventMap // Delay all events having the specified Group void DelayEvents(uint32 delay, uint32 groupId) { + if (!groupId || groupId > 8) + return; + uint32 nextTime = _time + delay; - uint32 groupMask = (1 << (groupId + 16)); + uint32 groupMask = (1 << (groupId + 15)); + for (StorageType::iterator itr = _eventMap.begin(); itr != _eventMap.end() && itr->first < nextTime;) { if (itr->second & groupMask) @@ -476,7 +494,10 @@ class EventMap // Cancel events belonging to specified group void CancelEventGroup(uint32 groupId) { - uint32 groupMask = (1 << (groupId + 16)); + if (!groupId || groupId > 8) + return; + + uint32 groupMask = (1 << (groupId + 15)); for (StorageType::iterator itr = _eventMap.begin(); itr != _eventMap.end();) { @@ -501,6 +522,12 @@ class EventMap return 0; } + // Returns wether the eventmap is in the given phase or not. + bool IsInPhase(uint32 phase) + { + return phase <= 8 && (!phase || _phase & (1 << phase + 23)); + } + private: uint32 _time; uint32 _phase; |