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
30{
32 CellArea(CellCoord low, CellCoord high) : low_bound(low), high_bound(high) { }
33
34 bool operator!() const { return low_bound == high_bound; }
35
36 void ResizeBorders(CellCoord& begin_cell, CellCoord& end_cell) const
37 {
38 begin_cell = low_bound;
39 end_cell = high_bound;
40 }
41
44};
45
46struct Cell
47{
48 Cell() : data() { }
49 explicit Cell(CellCoord const& p);
50 explicit Cell(float x, float y) : Cell(Trinity::ComputeCellCoord(x, y)) { }
51
52 void Compute(uint32 &x, uint32 &y) const
53 {
54 x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
55 y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
56 }
57
58 bool DiffCell(Cell const& cell) const
59 {
60 return(data.Part.cell_x != cell.data.Part.cell_x ||
61 data.Part.cell_y != cell.data.Part.cell_y);
62 }
63
64 bool DiffGrid(Cell const& cell) const
65 {
66 return(data.Part.grid_x != cell.data.Part.grid_x ||
67 data.Part.grid_y != cell.data.Part.grid_y);
68 }
69
70 uint32 CellX() const { return data.Part.cell_x; }
71 uint32 CellY() const { return data.Part.cell_y; }
72 uint32 GridX() const { return data.Part.grid_x; }
73 uint32 GridY() const { return data.Part.grid_y; }
74 bool NoCreate() const { return data.Part.nocreate; }
75 void SetNoCreate() { data.Part.nocreate = 1; }
76
78 {
79 return CellCoord(
80 data.Part.grid_x * MAX_NUMBER_OF_CELLS+data.Part.cell_x,
81 data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y);
82 }
83
84 bool operator == (Cell const& cell) const { return (data.All == cell.data.All); }
85 union
86 {
87 struct
88 {
97
98 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, WorldObject const& obj, float radius) const;
99 template<class T, class CONTAINER> void Visit(CellCoord const&, TypeContainerVisitor<T, CONTAINER>& visitor, Map&, float x, float y, float radius) const;
100
101 static CellArea CalculateCellArea(float x, float y, float radius);
102
103 template<class T> static void VisitGridObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
104 template<class T> static void VisitWorldObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
105 template<class T> static void VisitAllObjects(WorldObject const* obj, T& visitor, float radius, bool dont_load = true);
106
107 template<class T> static void VisitGridObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
108 template<class T> static void VisitWorldObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
109 template<class T> static void VisitAllObjects(float x, float y, Map* map, T& visitor, float radius, bool dont_load = true);
110
111private:
112 template<class T, class CONTAINER> void VisitCircle(TypeContainerVisitor<T, CONTAINER> &, Map &, CellCoord const&, CellCoord const&) const;
113};
114
115#endif
uint8_t uint8
Definition Define.h:135
uint64_t uint64
Definition Define.h:132
uint32_t uint32
Definition Define.h:133
#define MAX_NUMBER_OF_CELLS
Definition GridDefines.h:34
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition Map.h:281
CellCoord high_bound
Definition Cell.h:43
CellCoord low_bound
Definition Cell.h:42
bool operator!() const
Definition Cell.h:34
CellArea(CellCoord low, CellCoord high)
Definition Cell.h:32
CellArea()
Definition Cell.h:31
void ResizeBorders(CellCoord &begin_cell, CellCoord &end_cell) const
Definition Cell.h:36
Definition Cell.h:47
CellCoord GetCellCoord() const
Definition Cell.h:77
static void VisitAllObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition CellImpl.h:192
uint32 GridX() const
Definition Cell.h:72
uint64 All
Definition Cell.h:95
void SetNoCreate()
Definition Cell.h:75
Cell()
Definition Cell.h:48
bool NoCreate() const
Definition Cell.h:74
union Cell::@256 data
void Compute(uint32 &x, uint32 &y) const
Definition Cell.h:52
uint8 grid_x
Definition Cell.h:89
static void VisitGridObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition CellImpl.h:168
struct Cell::@256::@257 Part
uint32 GridY() const
Definition Cell.h:73
bool DiffGrid(Cell const &cell) const
Definition Cell.h:64
bool DiffCell(Cell const &cell) const
Definition Cell.h:58
bool operator==(Cell const &cell) const
Definition Cell.h:84
static void VisitWorldObjects(WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
Definition CellImpl.h:180
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition CellImpl.h:116
uint32 CellX() const
Definition Cell.h:70
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &obj, float radius) const
Definition CellImpl.h:50
Cell(float x, float y)
Definition Cell.h:50
uint32 CellY() const
Definition Cell.h:71
uint8 cell_y
Definition Cell.h:92
uint8 cell_x
Definition Cell.h:91
static CellArea CalculateCellArea(float x, float y, float radius)
Definition CellImpl.h:35
uint8 nocreate
Definition Cell.h:93
uint8 grid_y
Definition Cell.h:90