[2796] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / CellImpl.h
blobdcddcd08f2fcaa207d990098c1a6f0285875d2df
1 /*
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_CELLIMPL_H
20 #define MANGOS_CELLIMPL_H
22 #include "Cell.h"
23 #include "Map.h"
24 #include "RedZoneDistrict.h"
25 #include <cmath>
27 template<class LOCK_TYPE,class T, class CONTAINER>
28 inline void
29 Cell::Visit(const CellLock<LOCK_TYPE> &l, TypeContainerVisitor<T, CONTAINER> &visitor, Map &m) const
31 CellPair standing_cell = (const CellPair &)l;
32 CellPair cell_iter;
34 switch( (district_t)this->data.Part.reserved )
36 case ALL_DISTRICT:
38 CellPair update_cell(standing_cell);
39 update_cell << 1;
40 update_cell -= 1;
41 for(; abs(int(standing_cell.x_coord - update_cell.x_coord)) < 2; update_cell >> 1)
43 for(cell_iter=update_cell; abs(int(standing_cell.y_coord - cell_iter.y_coord)) < 2; cell_iter += 1)
45 Cell r_zone = RedZone::GetZone(cell_iter);
46 r_zone.data.Part.nocreate = l->data.Part.nocreate;
47 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
48 m.Visit(lock, visitor);
50 if (cell_iter.y_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
51 break;
54 if (cell_iter.x_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
55 break;
57 break;
59 case UPPER_LEFT_DISTRICT:
61 CellPair update_cell(standing_cell);
62 standing_cell << 1;
63 standing_cell -= 1;
65 for(cell_iter = update_cell; abs(int(standing_cell.x_coord - cell_iter.x_coord)) < 2; cell_iter >> 1)
67 Cell r_zone = RedZone::GetZone(cell_iter);
68 r_zone.data.Part.nocreate = l->data.Part.nocreate;
69 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
70 m.Visit(lock, visitor);
72 if (cell_iter.x_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
73 break;
76 for(cell_iter=update_cell, cell_iter += 1; abs(int(standing_cell.y_coord - cell_iter.y_coord)) < 2; cell_iter += 1)
78 Cell r_zone = RedZone::GetZone(cell_iter);
79 r_zone.data.Part.nocreate = l->data.Part.nocreate;
80 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
81 m.Visit(lock, visitor);
83 if (cell_iter.y_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
84 break;
86 break;
88 case UPPER_RIGHT_DISTRICT:
90 CellPair update_cell(standing_cell);
91 update_cell >> 1;
92 update_cell -= 1;
94 for(cell_iter = update_cell; abs(int(standing_cell.x_coord - cell_iter.x_coord)) < 2; cell_iter << 1)
96 Cell r_zone = RedZone::GetZone(cell_iter);
97 r_zone.data.Part.nocreate = l->data.Part.nocreate;
98 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
99 m.Visit(lock, visitor);
101 if (cell_iter.x_coord == 0)
102 break;
105 for(cell_iter=update_cell, cell_iter += 1; abs(int(standing_cell.y_coord - cell_iter.y_coord)) < 2; cell_iter += 1)
107 Cell r_zone = RedZone::GetZone(cell_iter);
108 r_zone.data.Part.nocreate = l->data.Part.nocreate;
109 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
110 m.Visit(lock, visitor);
112 if (cell_iter.y_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
113 break;
116 break;
118 case LOWER_LEFT_DISTRICT:
120 CellPair update_cell(standing_cell);
121 update_cell << 1;
122 update_cell += 1;
124 for(cell_iter = update_cell; abs(int(standing_cell.x_coord - cell_iter.x_coord)) < 2; cell_iter >> 1)
126 Cell r_zone = RedZone::GetZone(cell_iter);
127 r_zone.data.Part.nocreate = l->data.Part.nocreate;
128 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
129 m.Visit(lock, visitor);
131 if (cell_iter.x_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
132 break;
135 for(cell_iter=update_cell, cell_iter -= 1; abs(int(standing_cell.y_coord - cell_iter.y_coord)) < 2; cell_iter -= 1)
137 Cell r_zone = RedZone::GetZone(cell_iter);
138 r_zone.data.Part.nocreate = l->data.Part.nocreate;
139 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
140 m.Visit(lock, visitor);
142 if (cell_iter.y_coord == 0)
143 break;
146 break;
148 case LOWER_RIGHT_DISTRICT:
150 CellPair update_cell(standing_cell);
151 update_cell >> 1;
152 update_cell += 1;
154 for(cell_iter=update_cell; abs(int(standing_cell.x_coord - cell_iter.x_coord)) < 2; cell_iter << 1)
156 Cell r_zone = RedZone::GetZone(cell_iter);
157 r_zone.data.Part.nocreate = l->data.Part.nocreate;
158 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
159 m.Visit(lock, visitor);
161 if (cell_iter.x_coord == 0)
162 break;
165 for(cell_iter=update_cell, cell_iter -= 1; abs(int(standing_cell.y_coord - cell_iter.y_coord)) < 2; cell_iter -= 1)
167 Cell r_zone = RedZone::GetZone(cell_iter);
168 r_zone.data.Part.nocreate = l->data.Part.nocreate;
169 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
170 m.Visit(lock, visitor);
172 if (cell_iter.y_coord == 0)
173 break;
176 break;
178 case LEFT_DISTRICT:
180 CellPair update_cell(standing_cell);
181 update_cell << 1;
182 update_cell -= 1;
184 for(cell_iter=update_cell; abs(int(standing_cell.y_coord - cell_iter.y_coord)) < 2; cell_iter += 1)
186 Cell r_zone = RedZone::GetZone(cell_iter);
187 r_zone.data.Part.nocreate = l->data.Part.nocreate;
188 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
189 m.Visit(lock, visitor);
191 if (cell_iter.y_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
192 break;
195 break;
197 case RIGHT_DISTRICT:
199 CellPair update_cell(standing_cell);
200 update_cell >> 1;
201 update_cell -= 1;
203 for(cell_iter=update_cell; abs(int(standing_cell.y_coord - cell_iter.y_coord)) < 2; cell_iter += 1)
205 Cell r_zone = RedZone::GetZone(cell_iter);
206 r_zone.data.Part.nocreate = l->data.Part.nocreate;
207 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
208 m.Visit(lock, visitor);
210 if (cell_iter.y_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
211 break;
213 break;
215 case UPPER_DISTRICT:
217 CellPair update_cell(standing_cell);
218 update_cell << 1;
219 update_cell -= 1;
221 for(cell_iter=update_cell; abs(int(standing_cell.x_coord - cell_iter.x_coord)) < 2; cell_iter >> 1)
223 Cell r_zone = RedZone::GetZone(cell_iter);
224 r_zone.data.Part.nocreate = l->data.Part.nocreate;
225 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
226 m.Visit(lock, visitor);
228 if (cell_iter.x_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
229 break;
232 break;
234 case LOWER_DISTRICT:
236 CellPair update_cell(standing_cell);
237 update_cell << 1;
238 update_cell += 1;
240 for(cell_iter=update_cell; abs(int(standing_cell.x_coord - cell_iter.x_coord)) < 2; cell_iter >> 1)
242 Cell r_zone = RedZone::GetZone(cell_iter);
243 r_zone.data.Part.nocreate = l->data.Part.nocreate;
244 CellLock<LOCK_TYPE> lock(r_zone, cell_iter);
245 m.Visit(lock, visitor);
247 if (cell_iter.x_coord == TOTAL_NUMBER_OF_CELLS_PER_MAP-1)
248 break;
251 break;
253 case CENTER_DISTRICT:
255 m.Visit(l, visitor);
256 break;
258 default:
260 assert( false );
261 break;
265 #endif