[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / GridDefines.h
blobced42871bce22976936ecdd20d9be11a218dccc3
1 /*
2 * Copyright (C) 2005-2008 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 #ifndef MANGOS_GRIDDEFINES_H
20 #define MANGOS_GRIDDEFINES_H
22 #include "Common.h"
23 #include "GameSystem/NGrid.h"
24 #include <cmath>
26 // Forward class definitions
27 class Corpse;
28 class Creature;
29 class DynamicObject;
30 class GameObject;
31 class Pet;
32 class Player;
34 #define MAX_NUMBER_OF_GRIDS 64
36 #define SIZE_OF_GRIDS 533.33333f
37 #define CENTER_GRID_ID (MAX_NUMBER_OF_GRIDS/2)
39 #define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2)
41 #define MIN_GRID_DELAY MINUTE*1000
42 #define MIN_MAP_UPDATE_DELAY 50
44 #define MAX_NUMBER_OF_CELLS 4
45 #define SIZE_OF_GRID_CELL (SIZE_OF_GRIDS/MAX_NUMBER_OF_CELLS)
47 #define CENTER_GRID_CELL_ID 128
48 #define CENTER_GRID_CELL_OFFSET (SIZE_OF_GRID_CELL/2)
50 #define TOTAL_NUMBER_OF_CELLS_PER_MAP (MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_CELLS)
52 #define MAP_RESOLUTION 256
54 #define MAP_SIZE (SIZE_OF_GRIDS*MAX_NUMBER_OF_GRIDS)
55 #define MAP_HALFSIZE (MAP_SIZE/2)
57 // Creature used instead pet to simplify *::Visit templates (not required duplicate code for Creature->Pet case)
58 typedef TYPELIST_3(Player, Creature/*pets*/, Corpse/*resurrectable*/) AllWorldObjectTypes;
59 typedef TYPELIST_4(GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/) AllGridObjectTypes;
61 typedef GridRefManager<Corpse> CorpseMapType;
62 typedef GridRefManager<Creature> CreatureMapType;
63 typedef GridRefManager<DynamicObject> DynamicObjectMapType;
64 typedef GridRefManager<GameObject> GameObjectMapType;
65 typedef GridRefManager<Player> PlayerMapType;
67 typedef Grid<Player, AllWorldObjectTypes,AllGridObjectTypes> GridType;
68 typedef NGrid<8, Player, AllWorldObjectTypes, AllGridObjectTypes> NGridType;
70 typedef TypeMapContainer<AllGridObjectTypes> GridTypeMapContainer;
71 typedef TypeMapContainer<AllWorldObjectTypes> WorldTypeMapContainer;
73 template<const unsigned int LIMIT>
74 struct MANGOS_DLL_DECL CoordPair
76 CoordPair(uint32 x=0, uint32 y=0) : x_coord(x), y_coord(y) {}
77 CoordPair(const CoordPair<LIMIT> &obj) : x_coord(obj.x_coord), y_coord(obj.y_coord) {}
78 bool operator==(const CoordPair<LIMIT> &obj) const { return (obj.x_coord == x_coord && obj.y_coord == y_coord); }
79 bool operator!=(const CoordPair<LIMIT> &obj) const { return !operator==(obj); }
80 CoordPair<LIMIT>& operator=(const CoordPair<LIMIT> &obj)
82 x_coord = obj.x_coord;
83 y_coord = obj.y_coord;
84 return *this;
87 void operator<<(const uint32 val)
89 if( x_coord >= val )
90 x_coord -= val;
93 void operator>>(const uint32 val)
95 if( x_coord+val < LIMIT )
96 x_coord += val;
99 void operator-=(const uint32 val)
101 if( y_coord >= val )
102 y_coord -= val;
105 void operator+=(const uint32 val)
107 if( y_coord+val < LIMIT )
108 y_coord += val;
111 uint32 x_coord;
112 uint32 y_coord;
115 typedef CoordPair<MAX_NUMBER_OF_GRIDS> GridPair;
116 typedef CoordPair<TOTAL_NUMBER_OF_CELLS_PER_MAP> CellPair;
118 namespace MaNGOS
120 template<class RET_TYPE, int CENTER_VAL>
121 inline RET_TYPE Compute(float x, float y, float center_offset, float size)
123 // calculate and store temporary values in double format for having same result as same mySQL calculations
124 double x_offset = (double(x) - center_offset)/size;
125 double y_offset = (double(y) - center_offset)/size;
127 int x_val = int(x_offset+CENTER_VAL + 0.5);
128 int y_val = int(y_offset+CENTER_VAL + 0.5);
129 return RET_TYPE(x_val, y_val);
132 inline GridPair ComputeGridPair(float x, float y)
134 return Compute<GridPair, CENTER_GRID_ID>(x, y, CENTER_GRID_OFFSET, SIZE_OF_GRIDS);
137 inline CellPair ComputeCellPair(float x, float y)
139 return Compute<CellPair, CENTER_GRID_CELL_ID>(x, y, CENTER_GRID_CELL_OFFSET, SIZE_OF_GRID_CELL);
142 inline void NormalizeMapCoord(float &c)
144 if(c > MAP_HALFSIZE - 0.5)
145 c = MAP_HALFSIZE - 0.5;
146 else if(c < -(MAP_HALFSIZE - 0.5))
147 c = -(MAP_HALFSIZE - 0.5);
150 inline bool IsValidMapCoord(float c)
152 return finite(c) && (std::fabs(c) <= MAP_HALFSIZE - 0.5);
155 inline bool IsValidMapCoord(float x, float y)
157 return IsValidMapCoord(x) && IsValidMapCoord(y);
160 inline bool IsValidMapCoord(float x, float y, float z)
162 return IsValidMapCoord(x,y) && finite(z);
165 inline bool IsValidMapCoord(float x, float y, float z, float o)
167 return IsValidMapCoord(x,y,z) && finite(o);
170 #endif