2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "GridStates.h"
20 #include "GridNotifiers.h"
21 #include "GameSystem/Grid.h"
25 InvalidState::Update(Map
&, NGridType
&, GridInfo
&, const uint32
&/*x*/, const uint32
&/*y*/, const uint32
&) const
30 ActiveState::Update(Map
&m
, NGridType
&grid
, GridInfo
& info
, const uint32
&x
, const uint32
&y
, const uint32
&t_diff
) const
32 // Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle
33 info
.UpdateTimeTracker(t_diff
);
34 if( info
.getTimeTracker().Passed() )
36 if( grid
.ActiveObjectsInGrid() == 0 && !m
.ActiveObjectsNearGrid(x
, y
) )
38 ObjectGridStoper
stoper(grid
);
40 grid
.SetGridState(GRID_STATE_IDLE
);
44 m
.ResetGridExpiry(grid
, 0.1f
);
50 IdleState::Update(Map
&m
, NGridType
&grid
, GridInfo
&, const uint32
&x
, const uint32
&y
, const uint32
&) const
52 m
.ResetGridExpiry(grid
);
53 grid
.SetGridState(GRID_STATE_REMOVAL
);
54 sLog
.outDebug("Grid[%u,%u] on map %u moved to IDLE state", x
, y
, m
.GetId());
58 RemovalState::Update(Map
&m
, NGridType
&grid
, GridInfo
&info
, const uint32
&x
, const uint32
&y
, const uint32
&t_diff
) const
60 if(!info
.getUnloadLock())
62 info
.UpdateTimeTracker(t_diff
);
63 if( info
.getTimeTracker().Passed() )
65 if( !m
.UnloadGrid(x
, y
, false) )
67 sLog
.outDebug("Grid[%u,%u] for map %u differed unloading due to players or active objects nearby", x
, y
, m
.GetId());
68 m
.ResetGridExpiry(grid
);