[2] | 1 | /* |
---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
| 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. |
---|
| 8 | * |
---|
| 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. |
---|
| 13 | * |
---|
| 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 |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | #include "GridStates.h" |
---|
| 20 | #include "GridNotifiers.h" |
---|
| 21 | #include "ObjectAccessor.h" |
---|
| 22 | #include "GameSystem/Grid.h" |
---|
| 23 | #include "Log.h" |
---|
| 24 | |
---|
| 25 | void |
---|
| 26 | InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32 &/*x*/, const uint32 &/*y*/, const uint32 &) const |
---|
| 27 | { |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | void |
---|
| 31 | ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 &x, const uint32 &y, const uint32 &t_diff) const |
---|
| 32 | { |
---|
| 33 | // Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle |
---|
| 34 | info.UpdateTimeTracker(t_diff); |
---|
| 35 | if( info.getTimeTracker().Passed() ) |
---|
| 36 | { |
---|
| 37 | if( grid.ActiveObjectsInGrid() == 0 && !ObjectAccessor::Instance().PlayersNearGrid(x, y, m.GetId(), m.GetInstanceId()) ) |
---|
| 38 | { |
---|
| 39 | ObjectGridStoper stoper(grid); |
---|
| 40 | stoper.StopN(); |
---|
| 41 | grid.SetGridState(GRID_STATE_IDLE); |
---|
| 42 | } |
---|
| 43 | else |
---|
| 44 | { |
---|
| 45 | m.ResetGridExpiry(grid, 0.1f); |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | void |
---|
| 51 | IdleState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 &x, const uint32 &y, const uint32 &) const |
---|
| 52 | { |
---|
| 53 | m.ResetGridExpiry(grid); |
---|
| 54 | grid.SetGridState(GRID_STATE_REMOVAL); |
---|
| 55 | sLog.outDebug("Grid[%u,%u] on map %u moved to IDLE state", x, y, m.GetId()); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void |
---|
| 59 | RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 &x, const uint32 &y, const uint32 &t_diff) const |
---|
| 60 | { |
---|
| 61 | if(info.getUnloadFlag()) |
---|
| 62 | { |
---|
| 63 | info.UpdateTimeTracker(t_diff); |
---|
| 64 | if( info.getTimeTracker().Passed() ) |
---|
| 65 | { |
---|
| 66 | if( !m.UnloadGrid(x, y, false) ) |
---|
| 67 | { |
---|
| 68 | sLog.outDebug("Grid[%u,%u] for map %u differed unloading due to players nearby", x, y, m.GetId()); |
---|
| 69 | m.ResetGridExpiry(grid); |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | } |
---|
| 73 | } |
---|