| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "GridStates.h" |
|---|
| 22 | #include "GridNotifiers.h" |
|---|
| 23 | #include "ObjectAccessor.h" |
|---|
| 24 | #include "GameSystem/Grid.h" |
|---|
| 25 | #include "Log.h" |
|---|
| 26 | |
|---|
| 27 | void |
|---|
| 28 | InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32 &/*x*/, const uint32 &/*y*/, const uint32 &) const |
|---|
| 29 | { |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | void |
|---|
| 33 | ActiveState::Update(Map &m, NGridType &grid, GridInfo & info, const uint32 &x, const uint32 &y, const uint32 &t_diff) const |
|---|
| 34 | { |
|---|
| 35 | // Only check grid activity every (grid_expiry/10) ms, because it's really useless to do it every cycle |
|---|
| 36 | info.UpdateTimeTracker(t_diff); |
|---|
| 37 | if( info.getTimeTracker().Passed() ) |
|---|
| 38 | { |
|---|
| 39 | if( grid.ActiveObjectsInGrid() == 0 && !ObjectAccessor::Instance().PlayersNearGrid(x, y, m.GetId(), m.GetInstanceId()) ) |
|---|
| 40 | { |
|---|
| 41 | ObjectGridStoper stoper(grid); |
|---|
| 42 | stoper.StopN(); |
|---|
| 43 | grid.SetGridState(GRID_STATE_IDLE); |
|---|
| 44 | } |
|---|
| 45 | else |
|---|
| 46 | { |
|---|
| 47 | m.ResetGridExpiry(grid, 0.1f); |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | void |
|---|
| 53 | IdleState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 &x, const uint32 &y, const uint32 &) const |
|---|
| 54 | { |
|---|
| 55 | m.ResetGridExpiry(grid); |
|---|
| 56 | grid.SetGridState(GRID_STATE_REMOVAL); |
|---|
| 57 | sLog.outDebug("Grid[%u,%u] on map %u moved to IDLE state", x, y, m.GetId()); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | void |
|---|
| 61 | RemovalState::Update(Map &m, NGridType &grid, GridInfo &info, const uint32 &x, const uint32 &y, const uint32 &t_diff) const |
|---|
| 62 | { |
|---|
| 63 | if(info.getUnloadFlag()) |
|---|
| 64 | { |
|---|
| 65 | info.UpdateTimeTracker(t_diff); |
|---|
| 66 | if( info.getTimeTracker().Passed() ) |
|---|
| 67 | { |
|---|
| 68 | if( !m.UnloadGrid(x, y, false) ) |
|---|
| 69 | { |
|---|
| 70 | sLog.outDebug("Grid[%u,%u] for map %u differed unloading due to players nearby", x, y, m.GetId()); |
|---|
| 71 | m.ResetGridExpiry(grid); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | } |
|---|