Skip to content

Commit

Permalink
[10196] Use enum for instance reset event types, some related cleanup…
Browse files Browse the repository at this point in the history
… code.
  • Loading branch information
VladimirMangos committed Jul 15, 2010
1 parent 69421bf commit 8a48cb4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
24 changes: 12 additions & 12 deletions src/game/InstanceSaveMgr.cpp
Expand Up @@ -39,6 +39,8 @@

INSTANTIATE_SINGLETON_1( InstanceSaveManager );

static uint32 resetEventTypeDelay[MAX_RESET_EVENT_TYPE] = { 0, 3600, 900, 300, 60 };

//== InstanceSave functions ================================

InstanceSave::InstanceSave(uint16 MapId, uint32 InstanceId, Difficulty difficulty, time_t resetTime, bool canReset)
Expand Down Expand Up @@ -182,7 +184,7 @@ void InstanceResetScheduler::LoadResetTimes()
// schedule the reset times
for(InstResetTimeMapDiffType::iterator itr = instResetTime.begin(); itr != instResetTime.end(); ++itr)
if(itr->second.second > now)
ScheduleReset(true, itr->second.second, InstanceResetEvent(0, PAIR32_LOPART(itr->second.first),Difficulty(PAIR32_HIPART(itr->second.first)),itr->first));
ScheduleReset(true, itr->second.second, InstanceResetEvent(RESET_EVENT_DENGEON, PAIR32_LOPART(itr->second.first),Difficulty(PAIR32_HIPART(itr->second.first)),itr->first));
}

// load the global respawn times for raid/heroic instances
Expand Down Expand Up @@ -255,16 +257,15 @@ void InstanceResetScheduler::LoadResetTimes()
SetResetTimeFor(mapid,difficulty,t);

// schedule the global reset/warning
uint8 type = 1;
static int tim[4] = {3600, 900, 300, 60};
for(; type < 4; type++)
if(t - tim[type-1] > now)
ResetEventType type = RESET_EVENT_INFORM_1;
for(; type < RESET_EVENT_INFORM_LAST; type = ResetEventType(type+1))
if(t - resetEventTypeDelay[type] > now)
break;

for(ResetTimeMapDiffInstances::const_iterator in_itr = mapDiffResetInstances.lower_bound(map_diff_pair);
in_itr != mapDiffResetInstances.upper_bound(map_diff_pair); ++in_itr)
{
ScheduleReset(true, t - tim[type-1], InstanceResetEvent(type, mapid, difficulty, in_itr->second));
ScheduleReset(true, t - resetEventTypeDelay[type], InstanceResetEvent(type, mapid, difficulty, in_itr->second));
}
}
}
Expand Down Expand Up @@ -321,13 +322,12 @@ void InstanceResetScheduler::Update()
{
// global reset/warning for a certain map
time_t resetTime = GetResetTimeFor(event.mapid,event.difficulty);
m_InstanceSaves._ResetOrWarnAll(event.mapid, event.difficulty, event.type != 4, uint32(resetTime - now));
if(event.type != 4)
m_InstanceSaves._ResetOrWarnAll(event.mapid, event.difficulty, event.type != RESET_EVENT_INFORM_LAST, uint32(resetTime - now));
if(event.type != RESET_EVENT_INFORM_LAST)
{
// schedule the next warning/reset
event.type++;
static int tim[4] = {3600, 900, 300, 60};
ScheduleReset(true, resetTime - tim[event.type-1], event);
event.type = ResetEventType(event.type+1);
ScheduleReset(true, resetTime - resetEventTypeDelay[event.type], event);
}
m_resetTimeQueue.erase(m_resetTimeQueue.begin());
}
Expand Down Expand Up @@ -387,7 +387,7 @@ InstanceSave* InstanceSaveManager::AddInstanceSave(uint32 mapId, uint32 instance
{
resetTime = time(NULL) + 2 * HOUR;
// normally this will be removed soon after in InstanceMap::Add, prevent error
m_Scheduler.ScheduleReset(true, resetTime, InstanceResetEvent(0, mapId, difficulty, instanceId));
m_Scheduler.ScheduleReset(true, resetTime, InstanceResetEvent(RESET_EVENT_DENGEON, mapId, difficulty, instanceId));
}
}

Expand Down
21 changes: 16 additions & 5 deletions src/game/InstanceSaveMgr.h
Expand Up @@ -120,17 +120,28 @@ class InstanceSave
bool m_usedByMap; // true when instance map loaded
};

enum ResetEventType
{
RESET_EVENT_DENGEON = 0, // no fixed reset time
RESET_EVENT_INFORM_1 = 1, // raid/heroic warnings
RESET_EVENT_INFORM_2 = 2,
RESET_EVENT_INFORM_3 = 3,
RESET_EVENT_INFORM_LAST = 4,
};

#define MAX_RESET_EVENT_TYPE 5

/* resetTime is a global propery of each (raid/heroic) map
all instances of that map reset at the same time */
struct InstanceResetEvent
{
uint8 type;
Difficulty difficulty:8;
ResetEventType type :8;
Difficulty difficulty :8;
uint16 mapid;
uint16 instanceId;
uint32 instanceId;

InstanceResetEvent() : type(0), difficulty(DUNGEON_DIFFICULTY_NORMAL), mapid(0), instanceId(0) {}
InstanceResetEvent(uint8 t, uint32 _mapid, Difficulty d, uint16 _instanceid)
InstanceResetEvent() : type(RESET_EVENT_DENGEON), difficulty(DUNGEON_DIFFICULTY_NORMAL), mapid(0), instanceId(0) {}
InstanceResetEvent(ResetEventType t, uint32 _mapid, Difficulty d, uint32 _instanceid)
: type(t), difficulty(d), mapid(_mapid), instanceId(_instanceid) {}
bool operator == (const InstanceResetEvent& e) { return e.instanceId == instanceId; }
};
Expand Down
2 changes: 1 addition & 1 deletion src/game/Map.cpp
Expand Up @@ -1968,7 +1968,7 @@ void InstanceMap::SetResetSchedule(bool on)
// the reset time is only scheduled when there are no payers inside
// it is assumed that the reset time will rarely (if ever) change while the reset is scheduled
if(IsDungeon() && !HavePlayers() && !IsRaidOrHeroicDungeon())
sInstanceSaveMgr.GetScheduler().ScheduleReset(on, GetInstanceSave()->GetResetTime(), InstanceResetEvent(0, GetId(), Difficulty(GetSpawnMode()), GetInstanceId()));
sInstanceSaveMgr.GetScheduler().ScheduleReset(on, GetInstanceSave()->GetResetTime(), InstanceResetEvent(RESET_EVENT_DENGEON, GetId(), Difficulty(GetSpawnMode()), GetInstanceId()));
}

/* ******* Battleground Instance Maps ******* */
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10195"
#define REVISION_NR "10196"
#endif // __REVISION_NR_H__

0 comments on commit 8a48cb4

Please sign in to comment.