[2] | 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 | #ifndef MANGOS_GRIDDEFINES_H |
---|
| 20 | #define MANGOS_GRIDDEFINES_H |
---|
| 21 | |
---|
| 22 | #include "Common.h" |
---|
| 23 | #include "GameSystem/NGrid.h" |
---|
| 24 | #include <cmath> |
---|
| 25 | |
---|
| 26 | // Forward class definitions |
---|
| 27 | class Corpse; |
---|
| 28 | class Creature; |
---|
| 29 | class DynamicObject; |
---|
| 30 | class GameObject; |
---|
| 31 | class Pet; |
---|
| 32 | class Player; |
---|
| 33 | |
---|
| 34 | #define MAX_NUMBER_OF_GRIDS 64 |
---|
| 35 | |
---|
| 36 | #define SIZE_OF_GRIDS 533.33333f |
---|
| 37 | #define CENTER_GRID_ID (MAX_NUMBER_OF_GRIDS/2) |
---|
| 38 | |
---|
| 39 | #define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2) |
---|
| 40 | |
---|
| 41 | #define MIN_GRID_DELAY MINUTE*1000 |
---|
| 42 | #define MIN_MAP_UPDATE_DELAY 50 |
---|
| 43 | |
---|
| 44 | #define MAX_NUMBER_OF_CELLS 8 |
---|
| 45 | #define SIZE_OF_GRID_CELL (SIZE_OF_GRIDS/MAX_NUMBER_OF_CELLS) |
---|
| 46 | |
---|
| 47 | #define CENTER_GRID_CELL_ID 256 |
---|
| 48 | #define CENTER_GRID_CELL_OFFSET (SIZE_OF_GRID_CELL/2) |
---|
| 49 | |
---|
| 50 | #define TOTAL_NUMBER_OF_CELLS_PER_MAP (MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_CELLS) |
---|
| 51 | |
---|
| 52 | #define MAP_RESOLUTION 256 |
---|
| 53 | |
---|
| 54 | #define MAP_SIZE (SIZE_OF_GRIDS*MAX_NUMBER_OF_GRIDS) |
---|
| 55 | #define MAP_HALFSIZE (MAP_SIZE/2) |
---|
| 56 | |
---|
| 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; |
---|
| 60 | |
---|
| 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; |
---|
| 66 | |
---|
| 67 | typedef Grid<Player, AllWorldObjectTypes,AllGridObjectTypes> GridType; |
---|
| 68 | typedef NGrid<8, Player, AllWorldObjectTypes, AllGridObjectTypes> NGridType; |
---|
| 69 | |
---|
| 70 | typedef TypeMapContainer<AllGridObjectTypes> GridTypeMapContainer; |
---|
| 71 | typedef TypeMapContainer<AllWorldObjectTypes> WorldTypeMapContainer; |
---|
| 72 | |
---|
| 73 | template<const unsigned int LIMIT> |
---|
| 74 | struct MANGOS_DLL_DECL CoordPair |
---|
| 75 | { |
---|
| 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) |
---|
| 81 | { |
---|
| 82 | x_coord = obj.x_coord; |
---|
| 83 | y_coord = obj.y_coord; |
---|
| 84 | return *this; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void operator<<(const uint32 val) |
---|
| 88 | { |
---|
| 89 | if( x_coord >= val ) |
---|
| 90 | x_coord -= val; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | void operator>>(const uint32 val) |
---|
| 94 | { |
---|
| 95 | if( x_coord+val < LIMIT ) |
---|
| 96 | x_coord += val; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | void operator-=(const uint32 val) |
---|
| 100 | { |
---|
| 101 | if( y_coord >= val ) |
---|
| 102 | y_coord -= val; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | void operator+=(const uint32 val) |
---|
| 106 | { |
---|
| 107 | if( y_coord+val < LIMIT ) |
---|
| 108 | y_coord += val; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | uint32 x_coord; |
---|
| 112 | uint32 y_coord; |
---|
| 113 | }; |
---|
| 114 | |
---|
| 115 | typedef CoordPair<MAX_NUMBER_OF_GRIDS> GridPair; |
---|
| 116 | typedef CoordPair<TOTAL_NUMBER_OF_CELLS_PER_MAP> CellPair; |
---|
| 117 | |
---|
| 118 | namespace MaNGOS |
---|
| 119 | { |
---|
| 120 | template<class RET_TYPE, int CENTER_VAL> |
---|
| 121 | inline RET_TYPE Compute(float x, float y, float center_offset, float size) |
---|
| 122 | { |
---|
| 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; |
---|
| 126 | |
---|
| 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); |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | inline GridPair ComputeGridPair(float x, float y) |
---|
| 133 | { |
---|
| 134 | return Compute<GridPair, CENTER_GRID_ID>(x, y, CENTER_GRID_OFFSET, SIZE_OF_GRIDS); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | inline CellPair ComputeCellPair(float x, float y) |
---|
| 138 | { |
---|
| 139 | return Compute<CellPair, CENTER_GRID_CELL_ID>(x, y, CENTER_GRID_CELL_OFFSET, SIZE_OF_GRID_CELL); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | inline void NormalizeMapCoord(float &c) |
---|
| 143 | { |
---|
| 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); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | inline bool IsValidMapCoord(float c) |
---|
| 151 | { |
---|
| 152 | return finite(c) && (std::fabs(c) <= MAP_HALFSIZE - 0.5); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | inline bool IsValidMapCoord(float x, float y) |
---|
| 156 | { |
---|
| 157 | return IsValidMapCoord(x) && IsValidMapCoord(y); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | inline bool IsValidMapCoord(float x, float y, float z) |
---|
| 161 | { |
---|
| 162 | return IsValidMapCoord(x,y) && finite(z); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | inline bool IsValidMapCoord(float x, float y, float z, float o) |
---|
| 166 | { |
---|
| 167 | return IsValidMapCoord(x,y,z) && finite(o); |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | #endif |
---|