2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
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 "GameSystem/NGrid.h"
26 // Forward class definitions
33 #define MAX_NUMBER_OF_GRIDS 64
35 #define SIZE_OF_GRIDS 533.33333f
36 #define CENTER_GRID_ID (MAX_NUMBER_OF_GRIDS/2)
38 #define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2)
40 #define MIN_GRID_DELAY 60*1000
42 #define MAX_NUMBER_OF_CELLS 8
43 #define SIZE_OF_GRID_CELL (SIZE_OF_GRIDS/MAX_NUMBER_OF_CELLS)
45 #define CENTER_GRID_CELL_ID 256
46 #define CENTER_GRID_CELL_OFFSET (SIZE_OF_GRID_CELL/2)
48 #define TOTAL_NUMBER_OF_CELLS_PER_MAP (MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_CELLS)
50 #define MAP_RESOLUTION 256
52 #define MAP_SIZE (SIZE_OF_GRIDS*MAX_NUMBER_OF_GRIDS)
53 #define MAP_HALFSIZE (MAP_SIZE/2)
55 typedef TYPELIST_4(GameObject
, Creature
, DynamicObject
, Corpse
) AllObjectTypes
;
56 typedef Grid
<Player
, AllObjectTypes
> GridType
;
57 typedef std::map
<OBJECT_HANDLE
, Player
* > PlayerMapType
;
58 typedef std::map
<OBJECT_HANDLE
, Creature
* > CreatureMapType
;
59 typedef std::map
<OBJECT_HANDLE
, GameObject
* > GameObjectMapType
;
60 typedef std::map
<OBJECT_HANDLE
, DynamicObject
* > DynamicObjectMapType
;
61 typedef std::map
<OBJECT_HANDLE
, Corpse
* > CorpseMapType
;
63 typedef NGrid
<8, Player
, AllObjectTypes
> NGridType
;
65 template<const unsigned int LIMIT
>
66 struct MANGOS_DLL_DECL CoordPair
68 CoordPair(uint32 x
=0, uint32 y
=0) : x_coord(x
), y_coord(y
) {}
69 CoordPair(const CoordPair
<LIMIT
> &obj
) : x_coord(obj
.x_coord
), y_coord(obj
.y_coord
) {}
70 bool operator==(const CoordPair
<LIMIT
> &obj
) const { return (obj
.x_coord
== x_coord
&& obj
.y_coord
== y_coord
); }
71 bool operator!=(const CoordPair
<LIMIT
> &obj
) const { return !operator==(obj
); }
72 CoordPair
<LIMIT
>& operator=(const CoordPair
<LIMIT
> &obj
)
74 this->~CoordPair
<LIMIT
>();
75 new (this) CoordPair
<LIMIT
>(obj
);
79 void operator<<(const uint32 val
)
85 void operator>>(const uint32 val
)
87 if( x_coord
+val
< LIMIT
)
91 void operator-=(const uint32 val
)
97 void operator+=(const uint32 val
)
99 if( y_coord
+val
< LIMIT
)
107 typedef CoordPair
<MAX_NUMBER_OF_GRIDS
> GridPair
;
108 typedef CoordPair
<TOTAL_NUMBER_OF_CELLS_PER_MAP
> CellPair
;
112 template<class RET_TYPE
, int CENTER_VAL
>
113 inline RET_TYPE
Compute(float x
, float y
, float center_offset
, float size
)
115 // calculate and store temporary values in double format for having same result as same mySQL calcalations
116 double x_offset
= (double(x
) - center_offset
)/size
;
117 double y_offset
= (double(y
) - center_offset
)/size
;
119 int x_val
= int(x_offset
+CENTER_VAL
+ 0.5);
120 int y_val
= int(y_offset
+CENTER_VAL
+ 0.5);
121 return RET_TYPE(x_val
, y_val
);
124 inline GridPair
ComputeGridPair(float x
, float y
)
126 return Compute
<GridPair
, CENTER_GRID_ID
>(x
, y
, CENTER_GRID_OFFSET
, SIZE_OF_GRIDS
);
129 inline CellPair
ComputeCellPair(float x
, float y
)
131 return Compute
<CellPair
, CENTER_GRID_CELL_ID
>(x
, y
, CENTER_GRID_CELL_OFFSET
, SIZE_OF_GRID_CELL
);
134 inline void NormalizeMapCoord(float &c
)
136 if(c
> MAP_HALFSIZE
- 0.5)
137 c
= MAP_HALFSIZE
- 0.5;
138 else if(c
< -(MAP_HALFSIZE
- 0.5))
139 c
= -(MAP_HALFSIZE
- 0.5);
142 inline bool IsValidMapCoord(float c
)
144 return (std::abs(c
) < MAP_HALFSIZE
- 0.5);