2 * Copyright (C) 2005-2010 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
22 #include "GameSystem/TypeContainer.h"
23 #include "GameSystem/TypeContainerVisitor.h"
24 #include "GridDefines.h"
33 LOWER_DISTRICT
= 1 << 1,
34 LEFT_DISTRICT
= 1 << 2,
35 RIGHT_DISTRICT
= 1 << 3,
36 CENTER_DISTRICT
= 1 << 4,
37 UPPER_LEFT_DISTRICT
= (UPPER_DISTRICT
| LEFT_DISTRICT
),
38 UPPER_RIGHT_DISTRICT
= (UPPER_DISTRICT
| RIGHT_DISTRICT
),
39 LOWER_LEFT_DISTRICT
= (LOWER_DISTRICT
| LEFT_DISTRICT
),
40 LOWER_RIGHT_DISTRICT
= (LOWER_DISTRICT
| RIGHT_DISTRICT
),
41 ALL_DISTRICT
= (UPPER_DISTRICT
| LOWER_DISTRICT
| LEFT_DISTRICT
| RIGHT_DISTRICT
| CENTER_DISTRICT
)
44 struct MANGOS_DLL_DECL CellArea
46 CellArea() : right_offset(0), left_offset(0), upper_offset(0), lower_offset(0) {}
47 CellArea(int right
, int left
, int upper
, int lower
) : right_offset(right
), left_offset(left
), upper_offset(upper
), lower_offset(lower
) {}
48 bool operator!() const { return !right_offset
&& !left_offset
&& !upper_offset
&& !lower_offset
; }
50 void ResizeBorders(CellPair
& begin_cell
, CellPair
& end_cell
) const
52 begin_cell
<< left_offset
;
53 begin_cell
-= lower_offset
;
54 end_cell
>> right_offset
;
55 end_cell
+= upper_offset
;
64 struct MANGOS_DLL_DECL Cell
66 Cell() { data
.All
= 0; }
67 Cell(const Cell
&cell
) { data
.All
= cell
.data
.All
; }
68 explicit Cell(CellPair
const& p
);
70 void operator|=(Cell
&cell
)
72 data
.Part
.reserved
= 0;
73 cell
.data
.Part
.reserved
= 0;
74 uint32 x
, y
, old_x
, old_y
;
76 cell
.Compute(old_x
, old_y
);
78 if( std::abs(int(x
-old_x
)) > 1 || std::abs(int(y
-old_y
)) > 1)
80 data
.Part
.reserved
= ALL_DISTRICT
;
81 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
87 data
.Part
.reserved
|= LEFT_DISTRICT
;
88 cell
.data
.Part
.reserved
|= RIGHT_DISTRICT
;
92 data
.Part
.reserved
|= RIGHT_DISTRICT
;
93 cell
.data
.Part
.reserved
|= LEFT_DISTRICT
;
97 data
.Part
.reserved
|= UPPER_DISTRICT
;
98 cell
.data
.Part
.reserved
|= LOWER_DISTRICT
;
102 data
.Part
.reserved
|= LOWER_DISTRICT
;
103 cell
.data
.Part
.reserved
|= UPPER_DISTRICT
;
107 void Compute(uint32
&x
, uint32
&y
) const
109 x
= data
.Part
.grid_x
*MAX_NUMBER_OF_CELLS
+ data
.Part
.cell_x
;
110 y
= data
.Part
.grid_y
*MAX_NUMBER_OF_CELLS
+ data
.Part
.cell_y
;
113 bool DiffCell(const Cell
&cell
) const
115 return( data
.Part
.cell_x
!= cell
.data
.Part
.cell_x
||
116 data
.Part
.cell_y
!= cell
.data
.Part
.cell_y
);
119 bool DiffGrid(const Cell
&cell
) const
121 return( data
.Part
.grid_x
!= cell
.data
.Part
.grid_x
||
122 data
.Part
.grid_y
!= cell
.data
.Part
.grid_y
);
125 uint32
CellX() const { return data
.Part
.cell_x
; }
126 uint32
CellY() const { return data
.Part
.cell_y
; }
127 uint32
GridX() const { return data
.Part
.grid_x
; }
128 uint32
GridY() const { return data
.Part
.grid_y
; }
129 bool NoCreate() const { return data
.Part
.nocreate
; }
130 void SetNoCreate() { data
.Part
.nocreate
= 1; }
132 CellPair
cellPair() const
135 data
.Part
.grid_x
*MAX_NUMBER_OF_CELLS
+data
.Part
.cell_x
,
136 data
.Part
.grid_y
*MAX_NUMBER_OF_CELLS
+data
.Part
.cell_y
);
139 Cell
& operator=(const Cell
&cell
)
141 data
.All
= cell
.data
.All
;
145 bool operator==(const Cell
&cell
) const { return (data
.All
== cell
.data
.All
); }
146 bool operator!=(const Cell
&cell
) const { return !operator==(cell
); }
155 unsigned nocreate
: 1;
156 unsigned reserved
: 7;
161 template<class T
, class CONTAINER
> void Visit(const CellPair
&cellPair
, TypeContainerVisitor
<T
, CONTAINER
> &visitor
, Map
&) const;
162 template<class T
, class CONTAINER
> void Visit(const CellPair
&cellPair
, TypeContainerVisitor
<T
, CONTAINER
> &visitor
, Map
&m
, const WorldObject
&obj
, float radius
) const;
164 static CellArea
CalculateCellArea(const WorldObject
&obj
, float radius
);
167 template<class T
, class CONTAINER
> void VisitCircle(TypeContainerVisitor
<T
, CONTAINER
> &, Map
&, const CellPair
& , const CellPair
& ) const;