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
24 #include "RedZoneDistrict.h"
27 template<class LOCK_TYPE
,class T
, class CONTAINER
>
29 Cell::Visit(const CellLock
<LOCK_TYPE
> &l
, TypeContainerVisitor
<T
, CONTAINER
> &visitor
, Map
&m
) const
31 CellPair standing_cell
= (const CellPair
&)l
;
34 switch( (district_t
)this->data
.Part
.reserved
)
38 CellPair
update_cell(standing_cell
);
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)
54 if (cell_iter
.x_coord
== TOTAL_NUMBER_OF_CELLS_PER_MAP
-1)
59 case UPPER_LEFT_DISTRICT
:
61 CellPair
update_cell(standing_cell
);
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)
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)
88 case UPPER_RIGHT_DISTRICT
:
90 CellPair
update_cell(standing_cell
);
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)
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)
118 case LOWER_LEFT_DISTRICT
:
120 CellPair
update_cell(standing_cell
);
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)
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)
148 case LOWER_RIGHT_DISTRICT
:
150 CellPair
update_cell(standing_cell
);
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)
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)
180 CellPair
update_cell(standing_cell
);
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)
199 CellPair
update_cell(standing_cell
);
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)
217 CellPair
update_cell(standing_cell
);
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)
236 CellPair
update_cell(standing_cell
);
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)
253 case CENTER_DISTRICT
: