TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Cell.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITY_CELL_H
20 #define TRINITY_CELL_H
21 
22 #include <cmath>
23 
24 #include "TypeContainer.h"
25 #include "TypeContainerVisitor.h"
26 
27 #include "GridDefines.h"
28 
29 class Map;
30 class WorldObject;
31 
32 struct CellArea
33 {
34  CellArea() { }
35  CellArea(CellCoord low, CellCoord high) : low_bound(low), high_bound(high) { }
36 
37  bool operator!() const { return low_bound == high_bound; }
38 
39  void ResizeBorders(CellCoord& begin_cell, CellCoord& end_cell) const
40  {
41  begin_cell = low_bound;
42  end_cell = high_bound;
43  }
44 
47 };
48 
49 struct Cell
50 {
51  Cell() { data.All = 0; }
52  Cell(Cell const& cell) { data.All = cell.data.All; }
53  explicit Cell(CellCoord const& p);
54  explicit Cell(float x, float y);
55 
56  void Compute(uint32 &x, uint32 &y) const
57  {
58  x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
59  y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
60  }
61 
62  bool DiffCell(const Cell &cell) const
63  {
64  return(data.Part.cell_x != cell.data.Part.cell_x ||
65  data.Part.cell_y != cell.data.Part.cell_y);
66  }
67 
68  bool DiffGrid(const Cell &cell) const
69  {
70  return(data.Part.grid_x != cell.data.Part.grid_x ||
71  data.Part.grid_y != cell.data.Part.grid_y);
72  }
73 
74  uint32 CellX() const { return data.Part.cell_x; }
75  uint32 CellY() const { return data.Part.cell_y; }
76  uint32 GridX() const { return data.Part.grid_x; }
77  uint32 GridY() const { return data.Part.grid_y; }
78  bool NoCreate() const { return data.Part.nocreate; }
79  void SetNoCreate() { data.Part.nocreate = 1; }
80 
82  {
83  return CellCoord(
84  data.Part.grid_x * MAX_NUMBER_OF_CELLS+data.Part.cell_x,
85  data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y);
86  }
87 
88  Cell& operator=(Cell const& cell)
89  {
90  this->data.All = cell.data.All;
91  return *this;
92  }
93 
94  bool operator == (Cell const& cell) const { return (data.All == cell.data.All); }
95  bool operator != (Cell const& cell) const { return !operator == (cell); }
96  union
97  {
98  struct
99  {
100  unsigned grid_x : 6;
101  unsigned grid_y : 6;
102  unsigned cell_x : 6;
103  unsigned cell_y : 6;
104  unsigned nocreate : 1;
105  unsigned reserved : 7;
106  } Part;
108  } data;
109 
110  template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map &, WorldObject const&, float) const;
111  template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map &, float, float, float) const;
112 
113  static CellArea CalculateCellArea(float x, float y, float radius);
114 
115 private:
116  template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, CellCoord const&, CellCoord const&) const;
117 };
118 
119 #endif
struct Cell::@307::@308 Part
unsigned grid_y
Definition: Cell.h:101
Definition: TypeContainerVisitor.h:32
bool operator!() const
Definition: Cell.h:37
uint32 CellY() const
Definition: Cell.h:75
void Compute(uint32 &x, uint32 &y) const
Definition: Cell.h:56
Cell()
Definition: Cell.h:51
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:35
bool DiffCell(const Cell &cell) const
Definition: Cell.h:62
bool DiffGrid(const Cell &cell) const
Definition: Cell.h:68
union Cell::@307 data
unsigned grid_x
Definition: Cell.h:100
bool operator!=(Cell const &cell) const
Definition: Cell.h:95
void SetNoCreate()
Definition: Cell.h:79
Definition: Object.h:423
static CellArea CalculateCellArea(float x, float y, float radius)
Definition: CellImpl.h:49
CellArea()
Definition: Cell.h:34
unsigned cell_x
Definition: Cell.h:102
Cell & operator=(Cell const &cell)
Definition: Cell.h:88
unsigned cell_y
Definition: Cell.h:103
Definition: Cell.h:32
uint32 CellX() const
Definition: Cell.h:74
CellCoord low_bound
Definition: Cell.h:45
uint32 All
Definition: Cell.h:107
Cell(Cell const &cell)
Definition: Cell.h:52
CellArea(CellCoord low, CellCoord high)
Definition: Cell.h:35
uint32_t uint32
Definition: Define.h:150
G3D::int16 y
Definition: Vector2int16.h:38
bool operator==(Cell const &cell) const
Definition: Cell.h:94
uint32 GridY() const
Definition: Cell.h:77
CellCoord GetCellCoord() const
Definition: Cell.h:81
Definition: Map.h:259
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition: CellImpl.h:130
Definition: Cell.h:49
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition: GridDefines.h:172
bool NoCreate() const
Definition: Cell.h:78
CellCoord high_bound
Definition: Cell.h:46
G3D::int16 x
Definition: Vector2int16.h:37
void ResizeBorders(CellCoord &begin_cell, CellCoord &end_cell) const
Definition: Cell.h:39
unsigned reserved
Definition: Cell.h:105
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
Definition: CellImpl.h:122
uint32 GridX() const
Definition: Cell.h:76
unsigned nocreate
Definition: Cell.h:104