root/trunk/src/game/MapManager.h @ 260

Revision 260, 4.9 kB (checked in by yumileroy, 17 years ago)

*DB script table stucture change. Source Mangos. Also fix some bugs. Hopefully this rev will make program usable again.

Original author: megamage
Date: 2008-11-20 10:43:20-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.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#ifndef TRINITY_MAPMANAGER_H
22#define TRINITY_MAPMANAGER_H
23
24#include "Platform/Define.h"
25#include "Policies/Singleton.h"
26#include "zthread/Mutex.h"
27#include "Common.h"
28#include "Map.h"
29#include "GridStates.h"
30
31class Transport;
32
33class TRINITY_DLL_DECL MapManager : public Trinity::Singleton<MapManager, Trinity::ClassLevelLockable<MapManager, ZThread::Mutex> >
34{
35
36    friend class Trinity::OperatorNew<MapManager>;
37    typedef UNORDERED_MAP<uint32, Map*> MapMapType;
38    typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool>  MapMapPair;
39
40    public:
41
42        Map* GetMap(uint32, const WorldObject* obj);
43        Map* FindMap(uint32 mapid) { return _findMap(mapid); }
44        Map* FindMap(uint32 mapid, uint32 instanceId);
45
46        // only const version for outer users
47        Map const* GetBaseMap(uint32 id) const { return const_cast<MapManager*>(this)->_GetBaseMap(id); }
48        void DeleteInstance(uint32 mapid, uint32 instanceId);
49
50        inline uint16 GetAreaFlag(uint32 mapid, float x, float y) const
51        {
52            Map const* m = GetBaseMap(mapid);
53            return m->GetAreaFlag(x, y);
54        }
55        inline uint32 GetAreaId(uint32 mapid, float x, float y) { return Map::GetAreaId(GetAreaFlag(mapid, x, y),mapid); }
56        inline uint32 GetZoneId(uint32 mapid, float x, float y) { return Map::GetZoneId(GetAreaFlag(mapid, x, y),mapid); }
57
58        void Initialize(void);
59        void Update(time_t);
60
61        inline void SetGridCleanUpDelay(uint32 t)
62        {
63            if( t < MIN_GRID_DELAY )
64                i_gridCleanUpDelay = MIN_GRID_DELAY;
65            else
66                i_gridCleanUpDelay = t;
67        }
68
69        inline void SetMapUpdateInterval(uint32 t)
70        {
71            if( t > MIN_MAP_UPDATE_DELAY )
72                t = MIN_MAP_UPDATE_DELAY;
73
74            i_timer.SetInterval(t);
75            i_timer.Reset();
76        }
77
78        void LoadGrid(int mapid, float x, float y, const WorldObject* obj, bool no_unload = false);
79        void UnloadAll();
80
81        static bool ExistMapAndVMap(uint32 mapid, float x, float y);
82        static bool IsValidMAP(uint32 mapid);
83
84        static bool IsValidMapCoord(uint32 mapid, float x,float y)
85        {
86            return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y);
87        }
88
89        static bool IsValidMapCoord(uint32 mapid, float x,float y,float z)
90        {
91            return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y,z);
92        }
93
94        static bool IsValidMapCoord(uint32 mapid, float x,float y,float z,float o)
95        {
96            return IsValidMAP(mapid) && Trinity::IsValidMapCoord(x,y,z,o);
97        }
98
99        void DoDelayedMovesAndRemoves();
100
101        void LoadTransports();
102
103        typedef std::set<Transport *> TransportSet;
104        TransportSet m_Transports;
105
106        typedef std::map<uint32, TransportSet> TransportMap;
107        TransportMap m_TransportsByMap;
108
109        bool CanPlayerEnter(uint32 mapid, Player* player);
110        void RemoveBonesFromMap(uint32 mapid, uint64 guid, float x, float y);
111        inline uint32 GenerateInstanceId() { return ++i_MaxInstanceId; }
112        void InitMaxInstanceId();
113
114        /* statistics */
115        uint32 GetNumInstances();
116        uint32 GetNumPlayersInInstances();
117
118    private:
119        // debugging code, should be deleted some day
120        void checkAndCorrectGridStatesArray();              // just for debugging to find some memory overwrites
121        GridState* i_GridStates[MAX_GRID_STATE];            // shadow entries to the global array in Map.cpp
122        int i_GridStateErrorCount;
123    private:
124        MapManager();
125        ~MapManager();
126
127        MapManager(const MapManager &);
128        MapManager& operator=(const MapManager &);
129
130        Map* _GetBaseMap(uint32 id);
131        Map* _findMap(uint32 id) const
132        {
133            MapMapType::const_iterator iter = i_maps.find(id);
134            return (iter == i_maps.end() ? NULL : iter->second);
135        }
136
137        typedef Trinity::ClassLevelLockable<MapManager, ZThread::Mutex>::Lock Guard;
138        uint32 i_gridCleanUpDelay;
139        MapMapType i_maps;
140        IntervalTimer i_timer;
141
142        uint32 i_MaxInstanceId;
143};
144#endif
Note: See TracBrowser for help on using the browser.