[2] | 1 | /* |
---|
[102] | 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
| 3 | * |
---|
[44] | 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
[2] | 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 |
---|
[44] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
[2] | 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 |
---|
[44] | 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
[2] | 19 | */ |
---|
| 20 | |
---|
[44] | 21 | #ifndef TRINITY_GRIDDEFINES_H |
---|
| 22 | #define TRINITY_GRIDDEFINES_H |
---|
[2] | 23 | |
---|
| 24 | #include "Common.h" |
---|
| 25 | #include "GameSystem/NGrid.h" |
---|
| 26 | #include <cmath> |
---|
| 27 | |
---|
| 28 | // Forward class definitions |
---|
| 29 | class Corpse; |
---|
| 30 | class Creature; |
---|
| 31 | class DynamicObject; |
---|
| 32 | class GameObject; |
---|
| 33 | class Pet; |
---|
| 34 | class Player; |
---|
| 35 | |
---|
| 36 | #define MAX_NUMBER_OF_GRIDS 64 |
---|
| 37 | |
---|
| 38 | #define SIZE_OF_GRIDS 533.33333f |
---|
| 39 | #define CENTER_GRID_ID (MAX_NUMBER_OF_GRIDS/2) |
---|
| 40 | |
---|
| 41 | #define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2) |
---|
| 42 | |
---|
| 43 | #define MIN_GRID_DELAY MINUTE*1000 |
---|
| 44 | #define MIN_MAP_UPDATE_DELAY 50 |
---|
| 45 | |
---|
| 46 | #define MAX_NUMBER_OF_CELLS 8 |
---|
| 47 | #define SIZE_OF_GRID_CELL (SIZE_OF_GRIDS/MAX_NUMBER_OF_CELLS) |
---|
| 48 | |
---|
| 49 | #define CENTER_GRID_CELL_ID 256 |
---|
| 50 | #define CENTER_GRID_CELL_OFFSET (SIZE_OF_GRID_CELL/2) |
---|
| 51 | |
---|
| 52 | #define TOTAL_NUMBER_OF_CELLS_PER_MAP (MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_CELLS) |
---|
| 53 | |
---|
| 54 | #define MAP_RESOLUTION 256 |
---|
| 55 | |
---|
| 56 | #define MAP_SIZE (SIZE_OF_GRIDS*MAX_NUMBER_OF_GRIDS) |
---|
| 57 | #define MAP_HALFSIZE (MAP_SIZE/2) |
---|
| 58 | |
---|
| 59 | // Creature used instead pet to simplify *::Visit templates (not required duplicate code for Creature->Pet case) |
---|
[233] | 60 | typedef TYPELIST_4(Player, Creature/*pets*/, Corpse/*resurrectable*/, DynamicObject/*farsight target*/) AllWorldObjectTypes; |
---|
[2] | 61 | typedef TYPELIST_4(GameObject, Creature/*except pets*/, DynamicObject, Corpse/*Bones*/) AllGridObjectTypes; |
---|
| 62 | |
---|
| 63 | typedef GridRefManager<Corpse> CorpseMapType; |
---|
| 64 | typedef GridRefManager<Creature> CreatureMapType; |
---|
| 65 | typedef GridRefManager<DynamicObject> DynamicObjectMapType; |
---|
| 66 | typedef GridRefManager<GameObject> GameObjectMapType; |
---|
| 67 | typedef GridRefManager<Player> PlayerMapType; |
---|
| 68 | |
---|
| 69 | typedef Grid<Player, AllWorldObjectTypes,AllGridObjectTypes> GridType; |
---|
| 70 | typedef NGrid<8, Player, AllWorldObjectTypes, AllGridObjectTypes> NGridType; |
---|
| 71 | |
---|
| 72 | typedef TypeMapContainer<AllGridObjectTypes> GridTypeMapContainer; |
---|
| 73 | typedef TypeMapContainer<AllWorldObjectTypes> WorldTypeMapContainer; |
---|
| 74 | |
---|
| 75 | template<const unsigned int LIMIT> |
---|
[44] | 76 | struct TRINITY_DLL_DECL CoordPair |
---|
[2] | 77 | { |
---|
| 78 | CoordPair(uint32 x=0, uint32 y=0) : x_coord(x), y_coord(y) {} |
---|
| 79 | CoordPair(const CoordPair<LIMIT> &obj) : x_coord(obj.x_coord), y_coord(obj.y_coord) {} |
---|
| 80 | bool operator==(const CoordPair<LIMIT> &obj) const { return (obj.x_coord == x_coord && obj.y_coord == y_coord); } |
---|
| 81 | bool operator!=(const CoordPair<LIMIT> &obj) const { return !operator==(obj); } |
---|
| 82 | CoordPair<LIMIT>& operator=(const CoordPair<LIMIT> &obj) |
---|
| 83 | { |
---|
| 84 | x_coord = obj.x_coord; |
---|
| 85 | y_coord = obj.y_coord; |
---|
| 86 | return *this; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | void operator<<(const uint32 val) |
---|
| 90 | { |
---|
| 91 | if( x_coord >= val ) |
---|
| 92 | x_coord -= val; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | void operator>>(const uint32 val) |
---|
| 96 | { |
---|
| 97 | if( x_coord+val < LIMIT ) |
---|
| 98 | x_coord += val; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | void operator-=(const uint32 val) |
---|
| 102 | { |
---|
| 103 | if( y_coord >= val ) |
---|
| 104 | y_coord -= val; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | void operator+=(const uint32 val) |
---|
| 108 | { |
---|
| 109 | if( y_coord+val < LIMIT ) |
---|
| 110 | y_coord += val; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | uint32 x_coord; |
---|
| 114 | uint32 y_coord; |
---|
| 115 | }; |
---|
| 116 | |
---|
| 117 | typedef CoordPair<MAX_NUMBER_OF_GRIDS> GridPair; |
---|
| 118 | typedef CoordPair<TOTAL_NUMBER_OF_CELLS_PER_MAP> CellPair; |
---|
| 119 | |
---|
[44] | 120 | namespace Trinity |
---|
[2] | 121 | { |
---|
| 122 | template<class RET_TYPE, int CENTER_VAL> |
---|
| 123 | inline RET_TYPE Compute(float x, float y, float center_offset, float size) |
---|
| 124 | { |
---|
| 125 | // calculate and store temporary values in double format for having same result as same mySQL calculations |
---|
| 126 | double x_offset = (double(x) - center_offset)/size; |
---|
| 127 | double y_offset = (double(y) - center_offset)/size; |
---|
| 128 | |
---|
| 129 | int x_val = int(x_offset+CENTER_VAL + 0.5); |
---|
| 130 | int y_val = int(y_offset+CENTER_VAL + 0.5); |
---|
| 131 | return RET_TYPE(x_val, y_val); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | inline GridPair ComputeGridPair(float x, float y) |
---|
| 135 | { |
---|
| 136 | return Compute<GridPair, CENTER_GRID_ID>(x, y, CENTER_GRID_OFFSET, SIZE_OF_GRIDS); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | inline CellPair ComputeCellPair(float x, float y) |
---|
| 140 | { |
---|
| 141 | return Compute<CellPair, CENTER_GRID_CELL_ID>(x, y, CENTER_GRID_CELL_OFFSET, SIZE_OF_GRID_CELL); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | inline void NormalizeMapCoord(float &c) |
---|
| 145 | { |
---|
| 146 | if(c > MAP_HALFSIZE - 0.5) |
---|
| 147 | c = MAP_HALFSIZE - 0.5; |
---|
| 148 | else if(c < -(MAP_HALFSIZE - 0.5)) |
---|
| 149 | c = -(MAP_HALFSIZE - 0.5); |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | inline bool IsValidMapCoord(float c) |
---|
| 153 | { |
---|
| 154 | return finite(c) && (std::fabs(c) <= MAP_HALFSIZE - 0.5); |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | inline bool IsValidMapCoord(float x, float y) |
---|
| 158 | { |
---|
| 159 | return IsValidMapCoord(x) && IsValidMapCoord(y); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | inline bool IsValidMapCoord(float x, float y, float z) |
---|
| 163 | { |
---|
| 164 | return IsValidMapCoord(x,y) && finite(z); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | inline bool IsValidMapCoord(float x, float y, float z, float o) |
---|
| 168 | { |
---|
| 169 | return IsValidMapCoord(x,y,z) && finite(o); |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | #endif |
---|