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
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
>
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
)
44 uint16 district
= (District
)this->data
.Part
.reserved
;
45 if(district
== CENTER_DISTRICT
)
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
;
60 begin_cell
<< 1; begin_cell
-= 1; // upper left
61 end_cell
>> 1; end_cell
+= 1; // lower right
64 case UPPER_LEFT_DISTRICT
:
66 begin_cell
<< 1; begin_cell
-= 1; // upper left
69 case UPPER_RIGHT_DISTRICT
:
71 begin_cell
-= 1; // up
72 end_cell
>> 1; // right
75 case LOWER_LEFT_DISTRICT
:
77 begin_cell
<< 1; // left
78 end_cell
+= 1; // down
81 case LOWER_RIGHT_DISTRICT
:
83 end_cell
>> 1; end_cell
+= 1; // lower right
88 begin_cell
-= 1; // up
89 end_cell
>> 1; end_cell
+= 1; // lower right
94 begin_cell
<< 1; begin_cell
-= 1; // upper left
95 end_cell
+= 1; // down
100 begin_cell
<< 1; begin_cell
-= 1; // upper left
101 end_cell
>> 1; // right
106 begin_cell
<< 1; // left
107 end_cell
>> 1; end_cell
+= 1; // lower right
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
);