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
 
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 &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, bool dont_load=true)
 
template<class T >
static void VisitWorldObjects (WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
 
template<class T >
static void VisitAllObjects (WorldObject const *obj, T &visitor, float radius, bool dont_load=true)
 
template<class T >
static void VisitGridObjects (float x, float y, Map *map, T &visitor, float radius, bool dont_load=true)
 
template<class T >
static void VisitWorldObjects (float x, float y, Map *map, T &visitor, float radius, bool dont_load=true)
 
template<class T >
static void VisitAllObjects (float x, float y, Map *map, T &visitor, float radius, bool dont_load=true)
 

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
 

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::@292 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 data.Part.nocreate = 0;
32 data.Part.reserved = 0;
33}
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:34

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
36{
38 data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
39 data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
40 data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
41 data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
42 data.Part.nocreate = 0;
43 data.Part.reserved = 0;
44}
CellCoord ComputeCellCoord(float x, float y)
Definition: GridDefines.h:190
uint32 x_coord
Definition: GridDefines.h:152
uint32 y_coord
Definition: GridDefines.h:153

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
47{
48 if (radius <= 0.0f)
49 {
51 return CellArea(center, center);
52 }
53
54 CellCoord centerX = Acore::ComputeCellCoord(x - radius, y - radius).normalize();
55 CellCoord centerY = Acore::ComputeCellCoord(x + radius, y + radius).normalize();
56
57 return CellArea(centerX, centerY);
58}
Definition: Cell.h:28
CoordPair & normalize()
Definition: GridDefines.h:140

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

Referenced by 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 }
unsigned cell_y
Definition: Cell.h:98
unsigned cell_x
Definition: Cell.h:97
struct Cell::@292::@293 Part

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:96
unsigned grid_x
Definition: Cell.h:95

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
77 {
78 return CellCoord(
79 data.Part.grid_x * MAX_NUMBER_OF_CELLS + data.Part.cell_x,
80 data.Part.grid_y * MAX_NUMBER_OF_CELLS + data.Part.cell_y);
81 }
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition: GridDefines.h:169

References data, and MAX_NUMBER_OF_CELLS.

Referenced by ObjectWorldLoader::Visit(), and ObjectGridLoader::Visit().

◆ GridX()

◆ GridY()

◆ NoCreate()

bool Cell::NoCreate ( ) const
inline
73{ return data.Part.nocreate; }

References data.

Referenced by Map::Visit().

◆ operator!=()

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

References operator==().

◆ operator=()

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

References All, and data.

◆ operator==()

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

References All, and data.

Referenced by operator!=().

◆ SetNoCreate()

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

References CalculateCellArea(), data, CellArea::high_bound, CoordPair< LIMIT >::IsCoordValid(), CellArea::low_bound, nocreate, Part, 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
62{
63 //we should increase search radius by object's radius, otherwise
64 //we could have problems with huge creatures, which won't attack nearest players etc
65 Visit(standing_cell, visitor, map, obj.GetPositionX(), obj.GetPositionY(), radius + obj.GetCombatReach());
66}
void Visit(CellCoord const &, TypeContainerVisitor< T, CONTAINER > &visitor, Map &, WorldObject const &obj, float radius) const
Definition: CellImpl.h:61

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

Referenced by Spell::CheckSpellFocus(), WorldObject::GetCreaturesWithEntryInRange(), WorldSession::HandleTextEmoteOpcode(), Visit(), VisitAllObjects(), VisitGridObjects(), and VisitWorldObjects().

◆ VisitAllObjects() [1/2]

template<class T >
void Cell::VisitAllObjects ( float  x,
float  y,
Map map,
T &  visitor,
float  radius,
bool  dont_load = true 
)
inlinestatic
251{
253 Cell cell(p);
254 if (dont_load)
255 {
256 cell.SetNoCreate();
257 }
258
260 cell.Visit(p, wnotifier, *map, x, y, radius);
262 cell.Visit(p, gnotifier, *map, x, y, radius);
263}
Definition: TypeContainerVisitor.h:84

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

◆ VisitAllObjects() [2/2]

template<class T >
void Cell::VisitAllObjects ( WorldObject const *  obj,
T &  visitor,
float  radius,
bool  dont_load = true 
)
inlinestatic
207{
208 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
209 Cell cell(p);
210 if (dont_load)
211 {
212 cell.SetNoCreate();
213 }
214
216 cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
218 cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
219}

References Acore::ComputeCellCoord(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), SetNoCreate(), 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(), 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(), GameObject::Update(), TotemAI::UpdateAI(), npc_belnistrasz::npc_belnistraszAI::UpdateAI(), boss_naxxramas_misc::boss_naxxramas_miscAI::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
127{
128 //here is an algorithm for 'filling' circum-squared octagon
129 uint32 x_shift = (uint32)ceilf((end_cell.x_coord - begin_cell.x_coord) * 0.3f - 0.5f);
130 //lets calculate x_start/x_end coords for central strip...
131 const uint32 x_start = begin_cell.x_coord + x_shift;
132 const uint32 x_end = end_cell.x_coord - x_shift;
133
134 //visit central strip with constant width...
135 for (uint32 x = x_start; x <= x_end; ++x)
136 {
137 for (uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y)
138 {
139 CellCoord cellCoord(x, y);
140 Cell r_zone(cellCoord);
141 r_zone.data.Part.nocreate = this->data.Part.nocreate;
142 map.Visit(r_zone, visitor);
143 }
144 }
145
146 //if x_shift == 0 then we have too small cell area, which were already
147 //visited at previous step, so just return from procedure...
148 if (x_shift == 0)
149 return;
150
151 uint32 y_start = end_cell.y_coord;
152 uint32 y_end = begin_cell.y_coord;
153 //now we are visiting borders of an octagon...
154 for (uint32 step = 1; step <= (x_start - begin_cell.x_coord); ++step)
155 {
156 //each step reduces strip height by 2 cells...
157 y_end += 1;
158 y_start -= 1;
159 for (uint32 y = y_start; y >= y_end; --y)
160 {
161 //we visit cells symmetrically from both sides, heading from center to sides and from up to bottom
162 //e.g. filling 2 trapezoids after filling central cell strip...
163 CellCoord cellCoord_left(x_start - step, y);
164 Cell r_zone_left(cellCoord_left);
165 r_zone_left.data.Part.nocreate = this->data.Part.nocreate;
166 map.Visit(r_zone_left, visitor);
167
168 //right trapezoid cell visit
169 CellCoord cellCoord_right(x_end + step, y);
170 Cell r_zone_right(cellCoord_right);
171 r_zone_right.data.Part.nocreate = this->data.Part.nocreate;
172 map.Visit(r_zone_right, visitor);
173 }
174 }
175}

References data, nocreate, Part, 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,
bool  dont_load = true 
)
inlinestatic
223{
225 Cell cell(p);
226 if (dont_load)
227 {
228 cell.SetNoCreate();
229 }
230
232 cell.Visit(p, gnotifier, *map, x, y, radius);
233}

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

◆ VisitGridObjects() [2/2]

template<class T >
void Cell::VisitGridObjects ( WorldObject const *  obj,
T &  visitor,
float  radius,
bool  dont_load = true 
)
inlinestatic
179{
180 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
181 Cell cell(p);
182 if (dont_load)
183 {
184 cell.SetNoCreate();
185 }
186
188 cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
189}

References Acore::ComputeCellCoord(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), SetNoCreate(), 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(), LoadHelper(), 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,
bool  dont_load = true 
)
inlinestatic
237{
239 Cell cell(p);
240 if (dont_load)
241 {
242 cell.SetNoCreate();
243 }
244
246 cell.Visit(p, wnotifier, *map, x, y, radius);
247}

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

◆ VisitWorldObjects() [2/2]

template<class T >
void Cell::VisitWorldObjects ( WorldObject const *  obj,
T &  visitor,
float  radius,
bool  dont_load = true 
)
inlinestatic
193{
194 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
195 Cell cell(p);
196 if (dont_load)
197 {
198 cell.SetNoCreate();
199 }
200
202 cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
203}

References Acore::ComputeCellCoord(), WorldObject::GetMap(), Position::GetPositionX(), Position::GetPositionY(), SetNoCreate(), 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(), 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(), 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

◆ cell_y

unsigned Cell::cell_y

◆ 

◆ grid_x

unsigned Cell::grid_x

◆ grid_y

unsigned Cell::grid_y

◆ nocreate

unsigned Cell::nocreate

Referenced by Visit(), and VisitCircle().

◆ 

◆ reserved

unsigned Cell::reserved