OregonCore  revision be9e804-git
Your Favourite TBC server
Cell Struct Reference

#include <Cell.h>

Public Member Functions

 Cell ()
 
 Cell (Cell const &cell)
 
 Cell (CellCoord const &p)
 
 Cell (float x, float y)
 
void Compute (uint32 &x, uint32 &y) const
 
bool DiffCell (const Cell &cell) const
 
bool DiffGrid (const Cell &cell) const
 
uint32 CellX () const
 
uint32 CellY () const
 
uint32 GridX () const
 
uint32 GridY () const
 
bool NoCreate () const
 
void SetNoCreate ()
 
CellCoord GetCellCoord () const
 
Celloperator= (Cell const &cell)
 
bool operator== (Cell const &cell) const
 
bool operator!= (Cell const &cell) const
 
template<class T , class CONTAINER >
void Visit (CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
 
template<class T , class CONTAINER >
void Visit (CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, float, float, float) const
 

Static Public Member Functions

static CellArea CalculateCellArea (float x, float y, float radius)
 

Public Attributes

union {
   struct {
      unsigned   grid_x: 6
 
      unsigned   grid_y: 6
 
      unsigned   cell_x: 6
 
      unsigned   cell_y: 6
 
      unsigned   nocreate: 1
 
      unsigned   reserved: 7
 
   }   Part
 
   uint32   All
 
data
 
float v9 [16 *8+1][16 *8+1]
 
float v8 [16 *8][16 *8]
 

Private Member Functions

template<class T , class CONTAINER >
void VisitCircle (TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
 

Detailed Description

Definition at line 46 of file Cell.h.

Constructor & Destructor Documentation

Cell::Cell ( )
inline

Definition at line 48 of file Cell.h.

48 { data.All = 0; }
union Cell::@1 data
Cell::Cell ( Cell const &  cell)
inline

Definition at line 49 of file Cell.h.

References All, and data.

49 { data.All = cell.data.All; }
union Cell::@1 data
Cell::Cell ( CellCoord const &  p)
inlineexplicit

Definition at line 27 of file CellImpl.h.

References data, MAX_NUMBER_OF_CELLS, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

28 {
29  data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
30  data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
31  data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
32  data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
33  data.Part.nocreate = 0;
34  data.Part.reserved = 0;
35 }
union Cell::@1 data
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:43
Cell::Cell ( float  x,
float  y 
)
inlineexplicit

Definition at line 37 of file CellImpl.h.

References Oregon::ComputeCellCoord(), data, MAX_NUMBER_OF_CELLS, CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

38 {
40  data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
41  data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
42  data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
43  data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
44  data.Part.nocreate = 0;
45  data.Part.reserved = 0;
46 }
union Cell::@1 data
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:43
uint32 y_coord
Definition: GridDefines.h:142
uint32 x_coord
Definition: GridDefines.h:141
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167

Member Function Documentation

CellArea Cell::CalculateCellArea ( float  x,
float  y,
float  radius 
)
inlinestatic

Definition at line 48 of file CellImpl.h.

References Oregon::ComputeCellCoord(), and CoordPair< LIMIT >::normalize().

Referenced by Visit(), and Map::VisitNearbyCellsOf().

49 {
50  if (radius <= 0.0f)
51  {
53  return CellArea(center, center);
54  }
55 
56  CellCoord centerX = Oregon::ComputeCellCoord(x - radius, y - radius).normalize();
57  CellCoord centerY = Oregon::ComputeCellCoord(x + radius, y + radius).normalize();
58 
59  return CellArea(centerX, centerY);
60 }
CoordPair & normalize()
Definition: GridDefines.h:129
Definition: Cell.h:29
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:167
void Cell::Compute ( uint32 x,
uint32 y 
) const
inline

Definition at line 53 of file Cell.h.

References MAX_NUMBER_OF_CELLS.

54  {
55  x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
56  y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
57  }
union Cell::@1 data
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:43
bool Cell::DiffCell ( const Cell cell) const
inline

Definition at line 59 of file Cell.h.

References data, and Part.

Referenced by Map::CreatureCellRelocation(), and Map::CreatureRelocation().

60  {
61  return(data.Part.cell_x != cell.data.Part.cell_x ||
62  data.Part.cell_y != cell.data.Part.cell_y);
63  }
union Cell::@1 data
struct Cell::@1::@2 Part
bool Cell::DiffGrid ( const Cell cell) const
inline

Definition at line 65 of file Cell.h.

References data, and Part.

Referenced by Map::CreatureCellRelocation(), and Map::CreatureRelocation().

66  {
67  return(data.Part.grid_x != cell.data.Part.grid_x ||
68  data.Part.grid_y != cell.data.Part.grid_y);
69  }
union Cell::@1 data
struct Cell::@1::@2 Part
CellCoord Cell::GetCellCoord ( ) const
inline

Definition at line 78 of file Cell.h.

References MAX_NUMBER_OF_CELLS.

79  {
80  return CellCoord(
81  data.Part.grid_x * MAX_NUMBER_OF_CELLS+data.Part.cell_x,
82  data.Part.grid_y * MAX_NUMBER_OF_CELLS+data.Part.cell_y);
83  }
union Cell::@1 data
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:43
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition: GridDefines.h:146
bool Cell::NoCreate ( ) const
inline

Definition at line 75 of file Cell.h.

Referenced by Map::Visit().

75 { return data.Part.nocreate; }
union Cell::@1 data
bool Cell::operator!= ( Cell const &  cell) const
inline

Definition at line 92 of file Cell.h.

92 { return !operator == (cell); }
bool operator==(Cell const &cell) const
Definition: Cell.h:91
Cell& Cell::operator= ( Cell const &  cell)
inline

Definition at line 85 of file Cell.h.

References All, and data.

86  {
87  this->data.All = cell.data.All;
88  return *this;
89  }
union Cell::@1 data
bool Cell::operator== ( Cell const &  cell) const
inline

Definition at line 91 of file Cell.h.

References All, and data.

91 { return (data.All == cell.data.All); }
union Cell::@1 data
template<class T , class CONTAINER >
void Cell::Visit ( CellCoord const &  standing_cell,
TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
WorldObject const &  obj,
float  radius 
) const
inline

Definition at line 121 of file CellImpl.h.

References WorldObject::GetObjectSize(), Position::GetPositionX(), and Position::GetPositionY().

Referenced by Map::_FindGameObject(), WorldObject::BuildUpdate(), Creature::CallAssistance(), Creature::CallForHelp(), Spell::CheckCast(), Spell::CheckItems(), SmartScript::DoFindFriendlyCC(), CreatureEventAI::DoFindFriendlyCC(), SmartScript::DoFindFriendlyMissingBuff(), CreatureEventAI::DoFindFriendlyMissingBuff(), Creature::DoFleeToGetAssistance(), SmartScript::DoSelectLowestHpFriendly(), CreatureEventAI::DoSelectLowestHpFriendly(), SmartScript::FindCreatureNear(), SmartScript::FindGameObjectNear(), WorldObject::GetCreatureListWithEntryInGrid(), WorldObject::GetGameObjectListWithEntryInGrid(), ChatHandler::GetObjectGlobalyWithGuidOrNearWithDbGuid(), ScriptedAI::GetPlayerAtMinimumRange(), ChatHandler::HandleRespawnCommand(), GameObject::LookupFishingHoleAround(), WorldObject::MonsterSay(), WorldObject::MonsterTextEmote(), WorldObject::MonsterYell(), Map::ScriptsProcess(), Unit::SelectNearestPlayer(), Creature::SelectNearestTarget(), Creature::SelectNearestTargetInAttackDistance(), GameObject::TriggeringLinkedGameObject(), Map::UpdateObjectsVisibilityFor(), Map::UpdateObjectVisibility(), Oregon::DelayedUnitRelocation::Visit(), Map::VisitAll(), Map::VisitGrid(), and Map::VisitWorld().

122 {
123  //we should increase search radius by object's radius, otherwise
124  //we could have problems with huge creatures, which won't attack nearest players etc
125  Visit(standing_cell, visitor, map, radius + obj.GetObjectSize(), obj.GetPositionX(), obj.GetPositionY());
126 }
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &, float) const
Definition: CellImpl.h:121
template<class T , class CONTAINER >
void Cell::Visit ( CellCoord const &  standing_cell,
TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
float  radius,
float  x_off,
float  y_off 
) const
inline

Definition at line 63 of file CellImpl.h.

References CalculateCellArea(), data, CellArea::high_bound, CoordPair< LIMIT >::IsCoordValid(), CellArea::low_bound, Part, SIZE_OF_GRIDS, Map::Visit(), VisitCircle(), CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

64 {
65  if (!standing_cell.IsCoordValid())
66  return;
67 
68  //no jokes here... Actually placing ASSERT() here was good idea, but
69  //we had some problems with DynamicObjects, which pass radius = 0.0f (DB issue?)
70  //maybe it is better to just return when radius <= 0.0f?
71  if (radius <= 0.0f)
72  {
73  map.Visit(*this, visitor);
74  return;
75  }
76  //lets limit the upper value for search radius
77  if (radius > SIZE_OF_GRIDS)
78  radius = SIZE_OF_GRIDS;
79 
80  //lets calculate object coord offsets from cell borders.
81  CellArea area = Cell::CalculateCellArea(x_off, y_off, radius);
82  //if radius fits inside standing cell
83  if (!area)
84  {
85  map.Visit(*this, visitor);
86  return;
87  }
88 
89  //visit all cells, found in CalculateCellArea()
90  //if radius is known to reach cell area more than 4x4 then we should call optimized VisitCircle
91  //currently this technique works with MAX_NUMBER_OF_CELLS 16 and higher, with lower values
92  //there are nothing to optimize because SIZE_OF_GRID_CELL is too big...
93  if ((area.high_bound.x_coord > (area.low_bound.x_coord + 4)) && (area.high_bound.y_coord > (area.low_bound.y_coord + 4)))
94  {
95  VisitCircle(visitor, map, area.low_bound, area.high_bound);
96  return;
97  }
98 
99  //ALWAYS visit standing cell first!!! Since we deal with small radiuses
100  //it is very essential to call visitor for standing cell firstly...
101  map.Visit(*this, visitor);
102 
103  // loop the cell range
104  for (uint32 x = area.low_bound.x_coord; x <= area.high_bound.x_coord; ++x)
105  {
106  for (uint32 y = area.low_bound.y_coord; y <= area.high_bound.y_coord; ++y)
107  {
108  CellCoord cellCoord(x, y);
109  //lets skip standing cell since we already visited it
110  if (cellCoord != standing_cell)
111  {
112  Cell r_zone(cellCoord);
113  r_zone.data.Part.nocreate = this->data.Part.nocreate;
114  map.Visit(r_zone, visitor);
115  }
116  }
117  }
118 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:35
union Cell::@1 data
uint32 y_coord
Definition: GridDefines.h:142
static CellArea CalculateCellArea(float x, float y, float radius)
Definition: CellImpl.h:48
uint32 x_coord
Definition: GridDefines.h:141
Definition: Cell.h:29
CellCoord low_bound
Definition: Cell.h:42
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition: CellImpl.h:129
Definition: Cell.h:46
void Visit(const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
CellCoord high_bound
Definition: Cell.h:43
ACE_UINT32 uint32
Definition: Define.h:71
template<class T , class CONTAINER >
void Cell::VisitCircle ( TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
CellCoord const &  begin_cell,
CellCoord const &  end_cell 
) const
inlineprivate

Definition at line 129 of file CellImpl.h.

References data, Part, Map::Visit(), CoordPair< LIMIT >::x_coord, and CoordPair< LIMIT >::y_coord.

Referenced by Visit().

130 {
131  //here is an algorithm for 'filling' circum-squared octagon
132  uint32 x_shift = (uint32)ceilf((end_cell.x_coord - begin_cell.x_coord) * 0.3f - 0.5f);
133  //lets calculate x_start/x_end coords for central strip...
134  const uint32 x_start = begin_cell.x_coord + x_shift;
135  const uint32 x_end = end_cell.x_coord - x_shift;
136 
137  //visit central strip with constant width...
138  for (uint32 x = x_start; x <= x_end; ++x)
139  {
140  for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y)
141  {
142  CellCoord cellCoord(x, y);
143  Cell r_zone(cellCoord);
144  r_zone.data.Part.nocreate = this->data.Part.nocreate;
145  map.Visit(r_zone, visitor);
146  }
147  }
148 
149  //if x_shift == 0 then we have too small cell area, which were already
150  //visited at previous step, so just return from procedure...
151  if (x_shift == 0)
152  return;
153 
154  uint32 y_start = end_cell.y_coord;
155  uint32 y_end = begin_cell.y_coord;
156  //now we are visiting borders of an octagon...
157  for (uint32 step = 1; step <= (x_start - begin_cell.x_coord); ++step)
158  {
159  //each step reduces strip height by 2 cells...
160  y_end += 1;
161  y_start -= 1;
162  for (uint32 y = y_start; y >= y_end; --y)
163  {
164  //we visit cells symmetrically from both sides, heading from center to sides and from up to bottom
165  //e.g. filling 2 trapezoids after filling central cell strip...
166  CellCoord cellCoord_left(x_start - step, y);
167  Cell r_zone_left(cellCoord_left);
168  r_zone_left.data.Part.nocreate = this->data.Part.nocreate;
169  map.Visit(r_zone_left, visitor);
170 
171  //right trapezoid cell visit
172  CellCoord cellCoord_right(x_end + step, y);
173  Cell r_zone_right(cellCoord_right);
174  r_zone_right.data.Part.nocreate = this->data.Part.nocreate;
175  map.Visit(r_zone_right, visitor);
176  }
177  }
178 }
union Cell::@1 data
Definition: Cell.h:46
void Visit(const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
ACE_UINT32 uint32
Definition: Define.h:71

Member Data Documentation

uint32 Cell::All

Definition at line 104 of file Cell.h.

Referenced by Cell(), operator=(), and operator==().

unsigned Cell::cell_x

Definition at line 99 of file Cell.h.

unsigned Cell::cell_y

Definition at line 100 of file Cell.h.

unsigned Cell::grid_x

Definition at line 97 of file Cell.h.

unsigned Cell::grid_y

Definition at line 98 of file Cell.h.

unsigned Cell::nocreate

Definition at line 101 of file Cell.h.

struct { ... } Cell::Part
unsigned Cell::reserved

Definition at line 102 of file Cell.h.

float Cell::v8[16 *8][16 *8]

Definition at line 53 of file adtfile.h.

float Cell::v9[16 *8+1][16 *8+1]

Definition at line 52 of file adtfile.h.


The documentation for this struct was generated from the following files: