TrinityCore
Loading...
Searching...
No Matches
Cell.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITY_CELL_H
19#define TRINITY_CELL_H
20
21#include "TypeContainer.h"
23
24#include "GridDefines.h"
25
26class Map;
27class WorldObject;
28
36
37struct Cell
38{
39 Cell() : data() { }
40 explicit Cell(CellCoord const& p);
41 explicit Cell(float x, float y) : Cell(Trinity::ComputeCellCoord(x, y)) { }
42
43 void Compute(uint32 &x, uint32 &y) const
44 {
45 x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
46 y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
47 }
48
49 bool DiffCell(Cell const& cell) const
50 {
51 return(data.Part.cell_x != cell.data.Part.cell_x ||
52 data.Part.cell_y != cell.data.Part.cell_y);
53 }
54
55 bool DiffGrid(Cell const& cell) const
56 {
57 return(data.Part.grid_x != cell.data.Part.grid_x ||
58 data.Part.grid_y != cell.data.Part.grid_y);
59 }
60
61 uint32 CellX() const { return data.Part.cell_x; }
62 uint32 CellY() const { return data.Part.cell_y; }
63 uint32 GridX() const { return data.Part.grid_x; }
64 uint32 GridY() const { return data.Part.grid_y; }
65
67 {
68 return GridCoord(
69 data.Part.grid_x,
70 data.Part.grid_y);
71 }
72
74 {
75 return CellCoord(
76 data.Part.grid_x * MAX_NUMBER_OF_CELLS+data.Part.cell_x,
77 data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y);
78 }
79
80 bool operator == (Cell const& cell) const { return (data.All == cell.data.All); }
81 union
82 {
83 struct
84 {
92
93 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, WorldObject const& obj, float radius) const;
94 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, float x, float y, float radius) const;
95
96 static CellArea CalculateCellArea(float x, float y, float radius);
97
98 template<class T> static void VisitGridObjects(WorldObject const* obj, T& visitor, float radius);
99 template<class T> static void VisitWorldObjects(WorldObject const* obj, T& visitor, float radius);
100 template<class T> static void VisitAllObjects(WorldObject const* obj, T& visitor, float radius);
101
102 template<class T> static void VisitGridObjects(float x, float y, Map* map, T& visitor, float radius);
103 template<class T> static void VisitWorldObjects(float x, float y, Map* map, T& visitor, float radius);
104 template<class T> static void VisitAllObjects(float x, float y, Map* map, T& visitor, float radius);
105
106private:
107 template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, CellCoord const&, CellCoord const&) const;
108};
109
110#endif
uint8_t uint8
Definition Define.h:156
uint32_t uint32
Definition Define.h:154
#define MAX_NUMBER_OF_CELLS
Definition GridDefines.h:36
CoordPair< MAX_NUMBER_OF_GRIDS > GridCoord
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition Map.h:227
CellCoord high_bound
Definition Cell.h:34
CellCoord low_bound
Definition Cell.h:33
CellArea(CellCoord low, CellCoord high)
Definition Cell.h:31
Definition Cell.h:38
CellCoord GetCellCoord() const
Definition Cell.h:73
uint32 GridX() const
Definition Cell.h:63
Cell()
Definition Cell.h:39
static void VisitWorldObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:150
struct Cell::@301::@302 Part
void Compute(uint32 &x, uint32 &y) const
Definition Cell.h:43
uint8 grid_x
Definition Cell.h:85
uint32 GridY() const
Definition Cell.h:64
bool DiffGrid(Cell const &cell) const
Definition Cell.h:55
bool DiffCell(Cell const &cell) const
Definition Cell.h:49
bool operator==(Cell const &cell) const
Definition Cell.h:80
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition CellImpl.h:91
static void VisitAllObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:160
uint32 CellX() const
Definition Cell.h:61
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &obj, float radius) const
Definition CellImpl.h:48
Cell(float x, float y)
Definition Cell.h:41
uint32 CellY() const
Definition Cell.h:62
uint8 cell_y
Definition Cell.h:88
uint8 cell_x
Definition Cell.h:87
static CellArea CalculateCellArea(float x, float y, float radius)
Definition CellImpl.h:33
uint32 All
Definition Cell.h:90
GridCoord GetGridCoord() const
Definition Cell.h:66
union Cell::@301 data
static void VisitGridObjects(WorldObject const *obj, T &visitor, float radius)
Definition CellImpl.h:140
uint8 grid_y
Definition Cell.h:86