| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.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_CELLIMPL_H |
|---|
| 22 | #define TRINITY_CELLIMPL_H |
|---|
| 23 | |
|---|
| 24 | #include "Cell.h" |
|---|
| 25 | #include "Map.h" |
|---|
| 26 | #include <cmath> |
|---|
| 27 | |
|---|
| 28 | inline Cell::Cell(CellPair const& p) |
|---|
| 29 | { |
|---|
| 30 | data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS; |
|---|
| 31 | data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS; |
|---|
| 32 | data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS; |
|---|
| 33 | data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS; |
|---|
| 34 | data.Part.nocreate = 0; |
|---|
| 35 | data.Part.reserved = 0; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | template<class LOCK_TYPE,class T, class CONTAINER> |
|---|
| 39 | inline void |
|---|
| 40 | Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const |
|---|
| 41 | { |
|---|
| 42 | const CellPair &standing_cell = l.i_cellPair; |
|---|
| 43 | if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) |
|---|
| 44 | return; |
|---|
| 45 | |
|---|
| 46 | uint16 district = (District)this->data.Part.reserved; |
|---|
| 47 | if(district == CENTER_DISTRICT) |
|---|
| 48 | { |
|---|
| 49 | m.Visit(l, visitor); |
|---|
| 50 | return; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | // set up the cell range based on the district |
|---|
| 54 | // the overloaded operators handle range checking |
|---|
| 55 | CellPair begin_cell = standing_cell; |
|---|
| 56 | CellPair end_cell = standing_cell; |
|---|
| 57 | |
|---|
| 58 | switch( district ) |
|---|
| 59 | { |
|---|
| 60 | case ALL_DISTRICT: |
|---|
| 61 | { |
|---|
| 62 | begin_cell << 1; begin_cell -= 1; // upper left |
|---|
| 63 | end_cell >> 1; end_cell += 1; // lower right |
|---|
| 64 | break; |
|---|
| 65 | } |
|---|
| 66 | case UPPER_LEFT_DISTRICT: |
|---|
| 67 | { |
|---|
| 68 | begin_cell << 1; begin_cell -= 1; // upper left |
|---|
| 69 | break; |
|---|
| 70 | } |
|---|
| 71 | case UPPER_RIGHT_DISTRICT: |
|---|
| 72 | { |
|---|
| 73 | begin_cell -= 1; // up |
|---|
| 74 | end_cell >> 1; // right |
|---|
| 75 | break; |
|---|
| 76 | } |
|---|
| 77 | case LOWER_LEFT_DISTRICT: |
|---|
| 78 | { |
|---|
| 79 | begin_cell << 1; // left |
|---|
| 80 | end_cell += 1; // down |
|---|
| 81 | break; |
|---|
| 82 | } |
|---|
| 83 | case LOWER_RIGHT_DISTRICT: |
|---|
| 84 | { |
|---|
| 85 | end_cell >> 1; end_cell += 1; // lower right |
|---|
| 86 | break; |
|---|
| 87 | } |
|---|
| 88 | case LEFT_DISTRICT: |
|---|
| 89 | { |
|---|
| 90 | begin_cell -= 1; // up |
|---|
| 91 | end_cell >> 1; end_cell += 1; // lower right |
|---|
| 92 | break; |
|---|
| 93 | } |
|---|
| 94 | case RIGHT_DISTRICT: |
|---|
| 95 | { |
|---|
| 96 | begin_cell << 1; begin_cell -= 1; // upper left |
|---|
| 97 | end_cell += 1; // down |
|---|
| 98 | break; |
|---|
| 99 | } |
|---|
| 100 | case UPPER_DISTRICT: |
|---|
| 101 | { |
|---|
| 102 | begin_cell << 1; begin_cell -= 1; // upper left |
|---|
| 103 | end_cell >> 1; // right |
|---|
| 104 | break; |
|---|
| 105 | } |
|---|
| 106 | case LOWER_DISTRICT: |
|---|
| 107 | { |
|---|
| 108 | begin_cell << 1; // left |
|---|
| 109 | end_cell >> 1; end_cell += 1; // lower right |
|---|
| 110 | break; |
|---|
| 111 | } |
|---|
| 112 | default: |
|---|
| 113 | { |
|---|
| 114 | assert( false ); |
|---|
| 115 | break; |
|---|
| 116 | } |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | // loop the cell range |
|---|
| 120 | for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++) |
|---|
| 121 | { |
|---|
| 122 | for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; y++) |
|---|
| 123 | { |
|---|
| 124 | CellPair cell_pair(x,y); |
|---|
| 125 | Cell r_zone(cell_pair); |
|---|
| 126 | r_zone.data.Part.nocreate = l->data.Part.nocreate; |
|---|
| 127 | CellLock<LOCK_TYPE> lock(r_zone, cell_pair); |
|---|
| 128 | m.Visit(lock, visitor); |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | #endif |
|---|