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
47{ data.All = 0; }
union Cell::@289 data

References data.

◆ Cell() [2/4]

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

References All, and data.

◆ Cell() [3/4]

Cell::Cell ( CellCoord const &  p)
inlineexplicit
27{
28 data.Part.grid_x = p.x_coord / MAX_NUMBER_OF_CELLS;
29 data.Part.grid_y = p.y_coord / MAX_NUMBER_OF_CELLS;
30 data.Part.cell_x = p.x_coord % MAX_NUMBER_OF_CELLS;
31 data.Part.cell_y = p.y_coord % MAX_NUMBER_OF_CELLS;
32 data.Part.nocreate = 0;
33 data.Part.reserved = 0;
34}
#define MAX_NUMBER_OF_CELLS
Definition: GridDefines.h:35

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

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

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
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 }

References data, and MAX_NUMBER_OF_CELLS.

◆ DiffCell()

bool Cell::DiffCell ( const Cell cell) const
inline
59 {
60 return(data.Part.cell_x != cell.data.Part.cell_x ||
61 data.Part.cell_y != cell.data.Part.cell_y);
62 }
unsigned cell_y
Definition: Cell.h:99
struct Cell::@289::@290 Part
unsigned cell_x
Definition: Cell.h:98

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
65 {
66 return(data.Part.grid_x != cell.data.Part.grid_x ||
67 data.Part.grid_y != cell.data.Part.grid_y);
68 }
unsigned grid_y
Definition: Cell.h:97
unsigned grid_x
Definition: Cell.h:96

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
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 }
CoordPair< TOTAL_NUMBER_OF_CELLS_PER_MAP > CellCoord
Definition: GridDefines.h:170

References data, and MAX_NUMBER_OF_CELLS.

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

◆ GridX()

◆ GridY()

◆ NoCreate()

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

References data.

Referenced by Map::Visit().

◆ operator!=()

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

References operator==().

◆ operator=()

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

References All, and data.

◆ operator==()

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

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

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
252{
254 Cell cell(p);
255 if (dont_load)
256 {
257 cell.SetNoCreate();
258 }
259
261 cell.Visit(p, wnotifier, *map, x, y, radius);
263 cell.Visit(p, gnotifier, *map, x, y, radius);
264}
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
208{
209 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
210 Cell cell(p);
211 if (dont_load)
212 {
213 cell.SetNoCreate();
214 }
215
217 cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
219 cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
220}

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

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
224{
226 Cell cell(p);
227 if (dont_load)
228 {
229 cell.SetNoCreate();
230 }
231
233 cell.Visit(p, gnotifier, *map, x, y, radius);
234}

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
180{
181 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
182 Cell cell(p);
183 if (dont_load)
184 {
185 cell.SetNoCreate();
186 }
187
189 cell.Visit(p, gnotifier, *center_obj->GetMap(), *center_obj, radius);
190}

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

Referenced by boss_janalai::boss_janalaiAI::Boom(), 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(), boss_janalai::boss_janalaiAI::HatchAllEggs(), npc_janalai_hatcher::npc_janalai_hatcherAI::HatchEggs(), 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
238{
240 Cell cell(p);
241 if (dont_load)
242 {
243 cell.SetNoCreate();
244 }
245
247 cell.Visit(p, wnotifier, *map, x, y, radius);
248}

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
194{
195 CellCoord p(Acore::ComputeCellCoord(center_obj->GetPositionX(), center_obj->GetPositionY()));
196 Cell cell(p);
197 if (dont_load)
198 {
199 cell.SetNoCreate();
200 }
201
203 cell.Visit(p, wnotifier, *center_obj->GetMap(), *center_obj, radius);
204}

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