[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / CellImpl.h
blobb673bad7656edce7eb2d733b0ca717729925add7
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_CELLIMPL_H
20 #define MANGOS_CELLIMPL_H
22 #include "Cell.h"
23 #include "Map.h"
24 #include <cmath>
26 inline Cell::Cell(CellPair const& p)
28 data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
29 data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
30 data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
31 data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
32 data.Part.nocreate = 0;
33 data.Part.reserved = 0;
36 template<class LOCK_TYPE,class T, class CONTAINER>
37 inline void
38 Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const
40 const CellPair &standing_cell = l.i_cellPair;
41 if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
42 return;
44 uint16 district = (District)this->data.Part.reserved;
45 if(district == CENTER_DISTRICT)
47 m.Visit(l, visitor);
48 return;
51 // set up the cell range based on the district
52 // the overloaded operators handle range checking
53 CellPair begin_cell = standing_cell;
54 CellPair end_cell = standing_cell;
56 switch( district )
58 case ALL_DISTRICT:
60 begin_cell << 1; begin_cell -= 1; // upper left
61 end_cell >> 1; end_cell += 1; // lower right
62 break;
64 case UPPER_LEFT_DISTRICT:
66 begin_cell << 1; begin_cell -= 1; // upper left
67 break;
69 case UPPER_RIGHT_DISTRICT:
71 begin_cell -= 1; // up
72 end_cell >> 1; // right
73 break;
75 case LOWER_LEFT_DISTRICT:
77 begin_cell << 1; // left
78 end_cell += 1; // down
79 break;
81 case LOWER_RIGHT_DISTRICT:
83 end_cell >> 1; end_cell += 1; // lower right
84 break;
86 case LEFT_DISTRICT:
88 begin_cell -= 1; // up
89 end_cell >> 1; end_cell += 1; // lower right
90 break;
92 case RIGHT_DISTRICT:
94 begin_cell << 1; begin_cell -= 1; // upper left
95 end_cell += 1; // down
96 break;
98 case UPPER_DISTRICT:
100 begin_cell << 1; begin_cell -= 1; // upper left
101 end_cell >> 1; // right
102 break;
104 case LOWER_DISTRICT:
106 begin_cell << 1; // left
107 end_cell >> 1; end_cell += 1; // lower right
108 break;
110 default:
112 assert( false );
113 break;
117 // loop the cell range
118 for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++)
120 for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; y++)
122 CellPair cell_pair(x,y);
123 Cell r_zone(cell_pair);
124 r_zone.data.Part.nocreate = l->data.Part.nocreate;
125 CellLock<LOCK_TYPE> lock(r_zone, cell_pair);
126 m.Visit(lock, visitor);
130 #endif