root/trunk/src/game/GridStates.cpp @ 26

Revision 2, 2.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
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
25void
26InvalidState::Update(Map &, NGridType &, GridInfo &, const uint32 &/*x*/, const uint32 &/*y*/, const uint32 &) const
27{
28}
29
30void
31ActiveState::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
50void
51IdleState::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
58void
59RemovalState::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}
Note: See TracBrowser for help on using the browser.