AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
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
 
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 &obj, float radius) const
 
template<class T , class CONTAINER >
void Visit (CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, float x, float y, float radius) const
 

Static Public Member Functions

static CellArea CalculateCellArea (float x, float y, float radius)
 
template<class T >
static void VisitGridObjects (WorldObject const *obj, T &visitor, float radius)
 
template<class T >
static void VisitWorldObjects (WorldObject const *obj, T &visitor, float radius)
 
template<class T >
static void VisitAllObjects (WorldObject const *obj, T &visitor, float radius)
 
template<class T >
static void VisitGridObjects (float x, float y, Map *map, T &visitor, float radius)
 
template<class T >
static void VisitWorldObjects (float x, float y, Map *map, T &visitor, float radius)
 
template<class T >
static void VisitAllObjects (float x, float y, Map *map, T &visitor, float radius)
 

Public Attributes

union { 
 
   struct { 
 
      unsigned   grid_x: 8 
 
      unsigned   grid_y: 8 
 
      unsigned   cell_x: 8 
 
      unsigned   cell_y: 8 
 
   }   Part 
 
   uint32   All 
 
data 
 

Private Member Functions

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

Detailed Description

Constructor & Destructor Documentation

◆ Cell() [1/4]

Cell::Cell ( )
inline
46{ data.All = 0; }
union Cell::@293 data

References data.

◆ Cell() [2/4]

Cell::Cell ( Cell const &  cell)
inline
47{ data.All = cell.data.All; }

References All, and data.

◆ Cell() [3/4]

Cell::Cell ( CellCoord const &  p)
inlineexplicit
26{
27 data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
28 data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
29 data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
30 data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
31}
#define MAX_NUMBER_OF_CELLS
Definition MapDefines.h:25

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

◆ Cell() [4/4]

Cell::Cell ( float  x,
float  y 
)
inlineexplicit
34{
36 data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
37 data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
38 data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
39 data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
40}
CellCoord ComputeCellCoord(float x, float y)
Definition GridDefines.h:193
uint32 x_coord
Definition GridDefines.h:151
uint32 y_coord
Definition GridDefines.h:152

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

Member Function Documentation

◆ CalculateCellArea()

CellArea Cell::CalculateCellArea ( float  x,
float  y,
float  radius 
)
inlinestatic
43{
44 if (radius <= 0.0f)
45 {
47 return CellArea(center, center);
48 }
49
50 CellCoord centerX = Acore::ComputeCellCoord(x + radius, y + radius).normalize();
51 CellCoord centerY = Acore::ComputeCellCoord(x - radius, y - radius).normalize();
52
53 return CellArea(centerX, centerY);
54}
Definition Cell.h:28
CoordPair & normalize()
Definition GridDefines.h:139

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

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

◆ CellX()

◆ CellY()

◆ Compute()

void Cell::Compute ( uint32 x,
uint32 y 
) const
inline
52 {
53 x = data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x;
54 y = data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y;
55 }

References data, and MAX_NUMBER_OF_CELLS.

◆ DiffCell()

bool Cell::DiffCell ( const Cell cell) const
inline
58 {
59 return(data.Part.cell_x != cell.data.Part.cell_x ||
60 data.Part.cell_y != cell.data.Part.cell_y);
61 }
struct Cell::@293::@294 Part
unsigned cell_y
Definition Cell.h:96
unsigned cell_x
Definition Cell.h:95

References cell_x, cell_y, data, and Part.

Referenced by Map::CreatureRelocation(), Map::DynamicObjectRelocation(), Map::GameObjectRelocation(), and Map::PlayerRelocation().

◆ DiffGrid()

bool Cell::DiffGrid ( const Cell cell) const
inline
64 {
65 return(data.Part.grid_x != cell.data.Part.grid_x ||
66 data.Part.grid_y != cell.data.Part.grid_y);
67 }
unsigned grid_y
Definition Cell.h:94
unsigned grid_x
Definition Cell.h:93

References data, grid_x, grid_y, and Part.

Referenced by Map::CreatureRelocation(), Map::DynamicObjectRelocation(), Map::GameObjectRelocation(), Map::MoveAllCreaturesInMoveList(), Map::MoveAllDynamicObjectsInMoveList(), Map::MoveAllGameObjectsInMoveList(), and Map::PlayerRelocation().

◆ GetCellCoord()

CellCoord Cell::GetCellCoord ( ) const
inline
75 {
76 return CellCoord(
77 data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x,
78 data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y);
79 }
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition GridDefines.h:168

References data, and MAX_NUMBER_OF_CELLS.

◆ GridX()

◆ GridY()

◆ operator!=()

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

References operator==().

◆ operator=()

Cell & Cell::operator= ( Cell const &  cell)
inline
82 {
83 this->data.All = cell.data.All;
84 return *this;
85 }

References All, and data.

◆ operator==()

bool Cell::operator== ( Cell const &  cell) const
inline
87{ return (data.All == cell.data.All); }

References All, and data.

Referenced by operator!=().

◆ Visit() [1/2]

template<class T , class CONTAINER >
void Cell::Visit ( CellCoord const &  standing_cell,
TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
float  x,
float  y,
float  radius 
) const
inline
66{
67 if (!standing_cell.IsCoordValid())
68 return;
69
70 // no jokes here... Actually placing ASSERT() here was good idea, but
71 // we had some problems with DynamicObjects, which pass radius = 0.0f (DB issue?)
72 // maybe it is better to just return when radius <= 0.0f?
73 if (radius <= 0.0f)
74 {
75 map.Visit(*this, visitor);
76 return;
77 }
78 //lets limit the upper value for search radius
79 if (radius > SIZE_OF_GRIDS)
80 radius = SIZE_OF_GRIDS;
81
82 //lets calculate object coord offsets from cell borders.
83 CellArea area = Cell::CalculateCellArea(x_off, y_off, radius);
84 //if radius fits inside standing cell
85 if (!area)
86 {
87 map.Visit(*this, visitor);
88 return;
89 }
90
91 //visit all cells, found in CalculateCellArea()
92 //if radius is known to reach cell area more than 4x4 then we should call optimized VisitCircle
93 //currently this technique works with MAX_NUMBER_OF_CELLS 16 and higher, with lower values
94 //there are nothing to optimize because SIZE_OF_GRID_CELL is too big...
95 if ((area.high_bound.x_coord > (area.low_bound.x_coord + 4)) && (area.high_bound.y_coord > (area.low_bound.y_coord + 4)))
96 {
97 VisitCircle(visitor, map, area.low_bound, area.high_bound);
98 return;
99 }
100
101 // 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 Cell r_zone(cellCoord);
110 map.Visit(r_zone, visitor);
111 }
112 }
113}
std::uint32_t uint32
Definition Define.h:107
#define ASSERT
Definition Errors.h:68
#define SIZE_OF_GRIDS
Definition MapDefines.h:26
void Visit(const Cell &cell, TypeContainerVisitor< T, CONTAINER > &visitor)
Definition Map.h:706
CellCoord high_bound
Definition Cell.h:41
CellCoord low_bound
Definition Cell.h:40
Definition Cell.h:45
void VisitCircle(TypeContainerVisitor< T, CONTAINER > &, Map &, CellCoord const &, CellCoord const &) const
Definition CellImpl.h:116
static CellArea CalculateCellArea(float x, float y, float radius)
Definition CellImpl.h:42

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

◆ Visit() [2/2]

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
58{
59 //we should increase search radius by object's radius, otherwise
60 //we could have problems with huge creatures, which won't attack nearest players etc
61 Visit(standing_cell, visitor, map, obj.GetPositionX(), obj.GetPositionY(), radius + obj.GetCombatReach());
62}
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &obj, float radius) const
Definition CellImpl.h:57

References WorldObject::GetCombatReach(), Position::GetPositionX(), Position::GetPositionY(), and Visit().

Referenced by Spell::CheckSpellFocus(), Visit(), VisitAllObjects(), VisitAllObjects(), VisitGridObjects(), VisitGridObjects(), VisitWorldObjects(), and VisitWorldObjects().

◆ VisitAllObjects() [1/2]

template<class T >
void Cell::VisitAllObjects ( float  x,
float  y,
Map map,
T &  visitor,
float  radius 
)
inlinestatic
218{
220 Cell cell(p);
221
223 cell.Visit(p, wnotifier, *map, x, y, radius);
225 cell.Visit(p, gnotifier, *map, x, y, radius);
226}
Definition TypeContainerVisitor.h:84

References Acore::ComputeCellCoord(), and Visit().

◆ VisitAllObjects() [2/2]

template<class T >
void Cell::VisitAllObjects ( WorldObject const *  obj,
T &  visitor,
float  radius 
)
inlinestatic
186{
187 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
188 Cell cell(p);
189
191 cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
193 cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
194}

References Acore::ComputeCellCoord(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), and Visit().

Referenced by boss_ouro::CastGroundRupture(), SmartScript::DoFindClosestFriendlyInRange(), ScriptedAI::DoFindFriendlyCC(), ScriptedAI::DoFindFriendlyMissingBuff(), ScriptedAI::DoSelectLowestHpFriendly(), Spell::EffectForceDeselect(), Spell::EffectSanctuary(), Unit::ExecuteDelayedUnitAINotifyEvent(), Unit::ExecuteDelayedUnitRelocationEvent(), UnitAura::FillTargetMap(), DynObjAura::FillTargetMap(), WorldObject::FindNearestCreature(), WorldObject::GetCreaturesWithEntryInRange(), SmartScript::GetWorldObjectsInDist(), debug_commandscript::HandleDebugEnterVehicleCommand(), AuraEffect::HandleFeignDeath(), spell_zulfarrak_unlocking::HandleOpenLock(), AuraEffect::HandleRaidProcFromChargeWithValueAuraProc(), spell_vehicle_throw_passenger::HandleScript(), Unit::SelectNearbyNoTotemTarget(), Unit::SelectNearbyTarget(), Creature::SelectNearestTarget(), Creature::SelectNearestTargetInAttackDistance(), Unit::SetContestedPvP(), npc_simon_bunny::npc_simon_bunnyAI::StartGame(), Map::SummonCreature(), GameObject::Update(), TotemAI::UpdateAI(), npc_belnistrasz::npc_belnistraszAI::UpdateAI(), npc_pet_dk_ebon_gargoyle::npc_pet_dk_ebon_gargoyleAI::UpdateAI(), Unit::UpdateObjectVisibility(), and Player::UpdateVisibilityForPlayer().

◆ VisitCircle()

template<class T , class CONTAINER >
void Cell::VisitCircle ( TypeContainerVisitor< T, CONTAINER > &  visitor,
Map map,
CellCoord const &  begin_cell,
CellCoord const &  end_cell 
) const
inlineprivate
117{
118 //here is an algorithm for 'filling' circum-squared octagon
119 uint32 x_shift = (uint32)ceilf((end_cell.x_coord - begin_cell.x_coord) * 0.3f - 0.5f);
120 //lets calculate x_start/x_end coords for central strip...
121 const uint32 x_start = begin_cell.x_coord + x_shift;
122 const uint32 x_end = end_cell.x_coord - x_shift;
123
124 //visit central strip with constant width...
125 for (uint32 x = x_start; x <= x_end; ++x)
126 {
127 for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y)
128 {
129 CellCoord cellCoord(x, y);
130 Cell r_zone(cellCoord);
131 map.Visit(r_zone, visitor);
132 }
133 }
134
135 //if x_shift == 0 then we have too small cell area, which were already
136 //visited at previous step, so just return from procedure...
137 if (x_shift == 0)
138 return;
139
140 uint32 y_start = end_cell.y_coord;
141 uint32 y_end = begin_cell.y_coord;
142 //now we are visiting borders of an octagon...
143 for (uint32 step = 1; step <= (x_start - begin_cell.x_coord); ++step)
144 {
145 //each step reduces strip height by 2 cells...
146 y_end += 1;
147 y_start -= 1;
148 for (uint32 y = y_start; y >= y_end; --y)
149 {
150 //we visit cells symmetrically from both sides, heading from center to sides and from up to bottom
151 //e.g. filling 2 trapezoids after filling central cell strip...
152 CellCoord cellCoord_left(x_start - step, y);
153 Cell r_zone_left(cellCoord_left);
154 map.Visit(r_zone_left, visitor);
155
156 //right trapezoid cell visit
157 CellCoord cellCoord_right(x_end + step, y);
158 Cell r_zone_right(cellCoord_right);
159 map.Visit(r_zone_right, visitor);
160 }
161 }
162}

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

Referenced by Visit().

◆ VisitGridObjects() [1/2]

template<class T >
void Cell::VisitGridObjects ( float  x,
float  y,
Map map,
T &  visitor,
float  radius 
)
inlinestatic
198{
200 Cell cell(p);
201
203 cell.Visit(p, gnotifier, *map, x, y, radius);
204}

References Acore::ComputeCellCoord(), and Visit().

◆ VisitGridObjects() [2/2]

template<class T >
void Cell::VisitGridObjects ( WorldObject const *  obj,
T &  visitor,
float  radius 
)
inlinestatic
166{
167 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
168 Cell cell(p);
169
171 cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
172}

References Acore::ComputeCellCoord(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), and Visit().

Referenced by Creature::CallAssistance(), Creature::CallForHelp(), spell_gen_cannibalize::CheckIfCorpseNear(), spell_hun_pet_carrion_feeder::CheckIfCorpseNear(), npc_q24545_lich_king::npc_q24545_lich_kingAI::CleanAll(), SmartScript::DoFindFriendlyCC(), SmartScript::DoFindFriendlyMissingBuff(), Creature::DoFleeToGetAssistance(), SmartScript::DoSelectLowestHpFriendly(), SmartScript::DoSelectLowestHpPercentFriendly(), ValithriaDespawner::Execute(), npc_captain_arnath::npc_captain_arnathAI::FindFriendlyCreature(), WorldObject::FindNearestGameObject(), WorldObject::FindNearestGameObjectOfType(), WorldObject::GetCreatureListWithEntryInGrid(), WorldObject::GetDeadCreatureListInGrid(), WorldObject::GetGameObjectListWithEntryInGrid(), ChatHandler::GetNearbyGameObject(), mmaps_commandscript::HandleMmapTestArea(), misc_commandscript::HandleRespawnAllCommand(), npc_green_dragon_combat_trigger::npc_green_dragon_combat_triggerAI::JustEngagedWith(), GridObjectLoader::LoadCreatures(), GameObject::LookupFishingHoleAround(), at_icc_start_frostwing_gauntlet::OnTrigger(), boss_the_lich_king::boss_the_lich_kingAI::Reset(), Spell::SearchTargets(), npc_shadowpriest_sezziz::npc_shadowpriest_sezzizAI::UpdateAI(), npc_crok_scourgebane::npc_crok_scourgebaneAI::UpdateAI(), npc_q24545_lich_king::npc_q24545_lich_kingAI::UpdateAI(), and npc_crok_scourgebane::npc_crok_scourgebaneAI::WaypointStart().

◆ VisitWorldObjects() [1/2]

template<class T >
void Cell::VisitWorldObjects ( float  x,
float  y,
Map map,
T &  visitor,
float  radius 
)
inlinestatic
208{
210 Cell cell(p);
211
213 cell.Visit(p, wnotifier, *map, x, y, radius);
214}

References Acore::ComputeCellCoord(), and Visit().

◆ VisitWorldObjects() [2/2]

template<class T >
void Cell::VisitWorldObjects ( WorldObject const *  obj,
T &  visitor,
float  radius 
)
inlinestatic
176{
177 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
178 Cell cell(p);
179
181 cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
182}

References Acore::ComputeCellCoord(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), and Visit().

Referenced by WorldObject::BuildUpdate(), npc_hallows_end_soh::CastFires(), spell_gen_cannibalize::CheckIfCorpseNear(), spell_hun_pet_carrion_feeder::CheckIfCorpseNear(), npc_hallows_end_soh::CompleteQuest(), WorldObject::DestroyForNearbyPlayers(), Spell::EffectForceDeselect(), ScriptedAI::GetPlayerAtMinimumRange(), AuraEffect::HandleAuraDummy(), spell_q11010_q11102_q11023_choose_loc::HandleDummy(), WorldSession::HandleTextEmoteOpcode(), npc_clintar_spirit::npc_clintar_spiritAI::IsSummonedBy(), spell_love_is_in_the_air_romantic_picnic::OnPeriodic(), WorldObject::PlayRadiusMusic(), WorldObject::PlayRadiusSound(), Spell::SearchTargets(), WorldObject::SelectNearestPlayer(), AchievementMgr::SendAchievementEarned(), CreatureTextMgr::SendChatPacket(), WorldObject::SendMessageToSet(), Player::SendMessageToSet(), WorldObject::SendMessageToSetInRange(), Player::SendMessageToSetInRange(), Player::SendMessageToSetInRange(), Unit::Talk(), Unit::Talk(), BfCapturePoint::Update(), OPvPCapturePoint::Update(), OPvPCapturePointNA::Update(), GameObject::Update(), npc_brewfest_super_brew_trigger::UpdateAI(), npc_crok_scourgebane::npc_crok_scourgebaneAI::UpdateAI(), go_flames::go_flamesAI::UpdateAI(), go_heat::go_heatAI::UpdateAI(), go_midsummer_music::go_midsummer_musicAI::UpdateAI(), and WorldObject::UpdateObjectVisibility().

Member Data Documentation

◆ All

uint32 Cell::All

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

◆ cell_x

unsigned Cell::cell_x

Referenced by DiffCell().

◆ cell_y

unsigned Cell::cell_y

Referenced by DiffCell().

◆ [union]

◆ grid_x

unsigned Cell::grid_x

◆ grid_y

unsigned Cell::grid_y

◆ [struct]

struct { ... } Cell::Part

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