Files
TCPlayerbotCore/src/server/game/Grids/GridStates.cpp
T

72 lines
2.5 KiB
C++
Raw Normal View History

/*
2011-01-01 15:01:13 +01:00
* Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "GridStates.h"
#include "GridNotifiers.h"
2010-06-07 23:40:17 +02:00
#include "Grid.h"
2008-10-02 16:23:55 -05:00
#include "Log.h"
2009-10-17 15:51:44 -07:00
2011-10-24 23:33:17 +01:00
void InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32) const
2008-10-02 16:23:55 -05:00
{
}
2009-10-17 15:51:44 -07:00
2011-10-24 23:33:17 +01:00
void ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 t_diff) const
2008-10-02 16:23:55 -05:00
{
// Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle
info.UpdateTimeTracker(t_diff);
2010-04-07 22:59:46 +02:00
if (info.getTimeTracker().Passed())
2008-10-02 16:23:55 -05:00
{
2011-10-22 10:01:29 -04:00
if (grid.ActiveObjectsInGrid() == 0 && !m.ActiveObjectsNearGrid(grid))
2008-10-02 16:23:55 -05:00
{
ObjectGridStoper worker;
TypeContainerVisitor<ObjectGridStoper, GridTypeMapContainer> visitor(worker);
grid.VisitAllGrids(visitor);
2008-10-02 16:23:55 -05:00
grid.SetGridState(GRID_STATE_IDLE);
2011-10-22 10:01:29 -04:00
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to IDLE state", grid.getX(), grid.getY(), m.GetId());
2008-10-02 16:23:55 -05:00
}
else
{
m.ResetGridExpiry(grid, 0.1f);
}
}
}
2009-10-17 15:51:44 -07:00
2011-10-24 23:33:17 +01:00
void IdleState::Update(Map &m, NGridType &grid, GridInfo &, const uint32) const
2008-10-02 16:23:55 -05:00
{
m.ResetGridExpiry(grid);
grid.SetGridState(GRID_STATE_REMOVAL);
2011-10-22 10:01:29 -04:00
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] on map %u moved to REMOVAL state", grid.getX(), grid.getY(), m.GetId());
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2011-10-24 23:33:17 +01:00
void RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 t_diff) const
2008-10-02 16:23:55 -05:00
{
2010-04-07 19:14:10 +02:00
if (!info.getUnloadLock())
2008-10-02 16:23:55 -05:00
{
info.UpdateTimeTracker(t_diff);
2010-04-07 22:59:46 +02:00
if (info.getTimeTracker().Passed())
2008-10-02 16:23:55 -05:00
{
2011-10-22 10:01:29 -04:00
if (!m.UnloadGrid(grid, false))
2008-10-02 16:23:55 -05:00
{
2011-10-22 10:01:29 -04:00
sLog->outDebug(LOG_FILTER_MAPS, "Grid[%u, %u] for map %u differed unloading due to players or active objects nearby", grid.getX(), grid.getY(), m.GetId());
2008-10-02 16:23:55 -05:00
m.ResetGridExpiry(grid);
}
}
}
}
2009-02-17 20:07:49 -06:00