aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Maps
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2017-06-19 23:20:06 -0300
committerariel- <ariel-@users.noreply.github.com>2017-06-19 23:20:06 -0300
commit85a7d5ce9ac68b30da2277cc91d4b70358f1880d (patch)
treedf3d2084ee2e35008903c03178039b9c986e2d08 /src/server/game/Maps
parent052fc24315ace866ea1cf610e85df119b68100c9 (diff)
Core: ported headers cleanup from master branch
Diffstat (limited to 'src/server/game/Maps')
-rw-r--r--src/server/game/Maps/Map.cpp161
-rw-r--r--src/server/game/Maps/Map.h146
-rw-r--r--src/server/game/Maps/MapInstanced.cpp28
-rw-r--r--src/server/game/Maps/MapInstanced.h8
-rw-r--r--src/server/game/Maps/MapManager.cpp10
-rw-r--r--src/server/game/Maps/MapManager.h8
-rw-r--r--src/server/game/Maps/MapObject.h60
-rw-r--r--src/server/game/Maps/MapReference.cpp40
-rw-r--r--src/server/game/Maps/MapReference.h23
-rw-r--r--src/server/game/Maps/MapScripts.cpp68
-rw-r--r--src/server/game/Maps/TransportMgr.cpp73
-rw-r--r--src/server/game/Maps/TransportMgr.h28
-rw-r--r--src/server/game/Maps/ZoneScript.cpp24
-rw-r--r--src/server/game/Maps/ZoneScript.h12
14 files changed, 438 insertions, 251 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 4e9f9e27862..0793422f8ad 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -17,25 +17,31 @@
*/
#include "Map.h"
-#include "MapManager.h"
#include "Battleground.h"
-#include "MMapFactory.h"
#include "CellImpl.h"
+#include "DatabaseEnv.h"
#include "DisableMgr.h"
#include "DynamicTree.h"
+#include "GameObjectModel.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "GridStates.h"
#include "Group.h"
#include "InstanceScript.h"
+#include "Log.h"
#include "MapInstanced.h"
+#include "MapManager.h"
+#include "MMapFactory.h"
+#include "MotionMaster.h"
#include "ObjectAccessor.h"
+#include "ObjectGridLoader.h"
#include "ObjectMgr.h"
#include "Pet.h"
#include "ScriptMgr.h"
#include "Transport.h"
#include "Vehicle.h"
#include "VMapFactory.h"
+#include "World.h"
u_map_magic MapMagic = { {'M','A','P','S'} };
u_map_magic MapVersionMagic = { {'v','1','.','8'} };
@@ -188,11 +194,11 @@ void Map::LoadMap(int gx, int gy, bool reload)
sScriptMgr->OnUnloadGridMap(this, GridMaps[gx][gy], gx, gy);
delete (GridMaps[gx][gy]);
- GridMaps[gx][gy]=NULL;
+ GridMaps[gx][gy]=nullptr;
}
// map file name
- char* tmp = NULL;
+ char* tmp = nullptr;
int len = sWorld->GetDataPath().length() + strlen("maps/%03u%02u%02u.map") + 1;
tmp = new char[len];
snprintf(tmp, len, (char *)(sWorld->GetDataPath() + "maps/%03u%02u%02u.map").c_str(), GetId(), gx, gy);
@@ -255,8 +261,8 @@ i_scriptLock(false), _defaultLight(GetDefaultMapLight(id))
for (unsigned int j=0; j < MAX_NUMBER_OF_GRIDS; ++j)
{
//z code
- GridMaps[idx][j] =NULL;
- setNGrid(NULL, idx, j);
+ GridMaps[idx][j] =nullptr;
+ setNGrid(nullptr, idx, j);
}
}
@@ -361,7 +367,7 @@ void Map::SwitchGridContainers(Creature* obj, bool on)
}
NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY());
- ASSERT(ngrid != NULL);
+ ASSERT(ngrid != nullptr);
GridType &grid = ngrid->GetGridType(cell.CellX(), cell.CellY());
@@ -406,7 +412,7 @@ void Map::SwitchGridContainers(GameObject* obj, bool on)
}
NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY());
- ASSERT(ngrid != NULL);
+ ASSERT(ngrid != nullptr);
GridType &grid = ngrid->GetGridType(cell.CellX(), cell.CellY());
@@ -446,7 +452,7 @@ void Map::DeleteFromWorld(Transport* transport)
delete transport;
}
-void Map::EnsureGridCreated(const GridCoord &p)
+void Map::EnsureGridCreated(GridCoord const& p)
{
std::lock_guard<std::mutex> lock(_gridLock);
EnsureGridCreated_i(p);
@@ -454,7 +460,7 @@ void Map::EnsureGridCreated(const GridCoord &p)
//Create NGrid so the object can be added to it
//But object data is not loaded here
-void Map::EnsureGridCreated_i(const GridCoord &p)
+void Map::EnsureGridCreated_i(GridCoord const& p)
{
if (!getNGrid(p.x_coord, p.y_coord))
{
@@ -478,11 +484,11 @@ void Map::EnsureGridCreated_i(const GridCoord &p)
}
//Load NGrid and make it active
-void Map::EnsureGridLoadedForActiveObject(const Cell &cell, WorldObject* object)
+void Map::EnsureGridLoadedForActiveObject(Cell const& cell, WorldObject* object)
{
EnsureGridLoaded(cell);
NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
- ASSERT(grid != NULL);
+ ASSERT(grid != nullptr);
// refresh grid state & timer
if (grid->GetGridState() != GRID_STATE_ACTIVE)
@@ -494,12 +500,12 @@ void Map::EnsureGridLoadedForActiveObject(const Cell &cell, WorldObject* object)
}
//Create NGrid and load the object data in it
-bool Map::EnsureGridLoaded(const Cell &cell)
+bool Map::EnsureGridLoaded(Cell const& cell)
{
EnsureGridCreated(GridCoord(cell.GridX(), cell.GridY()));
NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
- ASSERT(grid != NULL);
+ ASSERT(grid != nullptr);
if (!isGridObjectDataLoaded(cell.GridX(), cell.GridY()))
{
TC_LOG_DEBUG("maps", "Loading grid[%u, %u] for map %u instance %u", cell.GridX(), cell.GridY(), GetId(), i_InstanceId);
@@ -649,7 +655,7 @@ bool Map::AddToMap(Transport* obj)
return true;
}
-bool Map::IsGridLoaded(const GridCoord &p) const
+bool Map::IsGridLoaded(GridCoord const& p) const
{
return (getNGrid(p.x_coord, p.y_coord) && isGridObjectDataLoaded(p.x_coord, p.y_coord));
}
@@ -683,7 +689,7 @@ void Map::VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Trinity::Obj
}
}
-void Map::Update(const uint32 t_diff)
+void Map::Update(uint32 t_diff)
{
_dynamicTree.update(t_diff);
/// update worldsessions for existing players
@@ -1593,7 +1599,7 @@ bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll)
ASSERT(i_objectsToRemove.empty());
delete &ngrid;
- setNGrid(NULL, x, y);
+ setNGrid(nullptr, x, y);
}
int gx = (MAX_NUMBER_OF_GRIDS - 1) - x;
int gy = (MAX_NUMBER_OF_GRIDS - 1) - y;
@@ -1614,7 +1620,7 @@ bool Map::UnloadGrid(NGridType& ngrid, bool unloadAll)
else
((MapInstanced*)m_parentMap)->RemoveGridMapReference(GridCoord(gx, gy));
- GridMaps[gx][gy] = NULL;
+ GridMaps[gx][gy] = nullptr;
}
TC_LOG_DEBUG("maps", "Unloading grid[%u, %u] for map %u finished", x, y, GetId());
return true;
@@ -1707,7 +1713,7 @@ GridMap::~GridMap()
unloadData();
}
-bool GridMap::loadData(const char* filename)
+bool GridMap::loadData(char const* filename)
{
// Unload old data if exist
unloadData();
@@ -2319,7 +2325,7 @@ inline GridMap* Map::GetGrid(float x, float y)
return GridMaps[gx][gy];
}
-float Map::GetWaterOrGroundLevel(uint32 phasemask, float x, float y, float z, float* ground /*= NULL*/, bool /*swim = false*/) const
+float Map::GetWaterOrGroundLevel(uint32 phasemask, float x, float y, float z, float* ground /*= nullptr*/, bool /*swim = false*/) const
{
if (const_cast<Map*>(this)->GetGrid(x, y))
{
@@ -2800,7 +2806,7 @@ void Map::SendInitSelf(Player* player)
WorldPacket packet;
data.BuildPacket(&packet);
- player->GetSession()->SendPacket(&packet);
+ player->SendDirectMessage(&packet);
}
void Map::SendInitTransports(Player* player)
@@ -2813,7 +2819,7 @@ void Map::SendInitTransports(Player* player)
WorldPacket packet;
transData.BuildPacket(&packet);
- player->GetSession()->SendPacket(&packet);
+ player->SendDirectMessage(&packet);
}
void Map::SendRemoveTransports(Player* player)
@@ -2826,7 +2832,7 @@ void Map::SendRemoveTransports(Player* player)
WorldPacket packet;
transData.BuildPacket(&packet);
- player->GetSession()->SendPacket(&packet);
+ player->SendDirectMessage(&packet);
}
inline void Map::setNGrid(NGridType *grid, uint32 x, uint32 y)
@@ -2856,12 +2862,12 @@ void Map::SendObjectUpdates()
for (UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter)
{
iter->second.BuildPacket(&packet);
- iter->first->GetSession()->SendPacket(&packet);
+ iter->first->SendDirectMessage(&packet);
packet.clear(); // clean the string
}
}
-void Map::DelayedUpdate(const uint32 t_diff)
+void Map::DelayedUpdate(uint32 t_diff)
{
for (_transportsUpdateIter = _transports.begin(); _transportsUpdateIter != _transports.end();)
{
@@ -3001,7 +3007,7 @@ uint32 Map::GetPlayersCountExceptGMs() const
void Map::SendToPlayers(WorldPacket* data) const
{
for (MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
- itr->GetSource()->GetSession()->SendPacket(data);
+ itr->GetSource()->SendDirectMessage(data);
}
bool Map::ActiveObjectsNearGrid(NGridType const& ngrid) const
@@ -3121,7 +3127,7 @@ template TC_GAME_API void Map::RemoveFromMap(DynamicObject*, bool);
InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent)
: Map(id, expiry, InstanceId, SpawnMode, _parent),
m_resetAfterUnload(false), m_unloadWhenEmpty(false),
- i_data(NULL), i_script_id(0)
+ i_data(nullptr), i_script_id(0)
{
//lets initialize visibility distance for dungeons
InstanceMap::InitVisibilityDistance();
@@ -3134,7 +3140,7 @@ InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 Spaw
InstanceMap::~InstanceMap()
{
delete i_data;
- i_data = NULL;
+ i_data = nullptr;
}
void InstanceMap::InitVisibilityDistance()
@@ -3203,7 +3209,7 @@ bool InstanceMap::AddPlayerToMap(Player* player)
// increase current instances (hourly limit)
if (!group || !group->isLFGGroup())
- player->AddInstanceEnterTime(GetInstanceId(), time(NULL));
+ player->AddInstanceEnterTime(GetInstanceId(), time(nullptr));
// get or create an instance save for the map
InstanceSave* mapSave = sInstanceSaveMgr->GetInstanceSave(GetInstanceId());
@@ -3264,7 +3270,7 @@ bool InstanceMap::AddPlayerToMap(Player* player)
data << uint32(60000);
data << uint32(i_data ? i_data->GetCompletedEncounterMask() : 0);
data << uint8(0);
- player->GetSession()->SendPacket(&data);
+ player->SendDirectMessage(&data);
player->SetPendingBind(mapSave->GetInstanceId(), 60000);
}
}
@@ -3301,7 +3307,7 @@ bool InstanceMap::AddPlayerToMap(Player* player)
return true;
}
-void InstanceMap::Update(const uint32 t_diff)
+void InstanceMap::Update(uint32 t_diff)
{
Map::Update(t_diff);
@@ -3323,7 +3329,7 @@ void InstanceMap::RemovePlayerFromMap(Player* player, bool remove)
void InstanceMap::CreateInstanceData(bool load)
{
- if (i_data != NULL)
+ if (i_data != nullptr)
return;
InstanceTemplate const* mInstance = sObjectMgr->GetInstanceTemplate(GetId());
@@ -3414,6 +3420,11 @@ bool InstanceMap::Reset(uint8 method)
return m_mapRefManager.isEmpty();
}
+std::string const& InstanceMap::GetScriptName() const
+{
+ return sObjectMgr->GetScriptName(i_script_id);
+}
+
void InstanceMap::PermBindAllPlayers()
{
if (!IsDungeon())
@@ -3451,7 +3462,7 @@ void InstanceMap::PermBindAllPlayers()
player->BindToInstance(save, true);
WorldPacket data(SMSG_INSTANCE_SAVE_CREATED, 4);
data << uint32(0);
- player->GetSession()->SendPacket(&data);
+ player->SendDirectMessage(&data);
player->GetSession()->SendCalendarRaidLockout(save, true);
// if group leader is in instance, group also gets bound
@@ -3501,6 +3512,74 @@ MapDifficulty const* Map::GetMapDifficulty() const
return GetMapDifficultyData(GetId(), GetDifficulty());
}
+uint32 Map::GetId() const
+{
+ return i_mapEntry->MapID;
+}
+
+bool Map::IsRegularDifficulty() const
+{
+ return GetDifficulty() == REGULAR_DIFFICULTY;
+}
+
+bool Map::Instanceable() const
+{
+ return i_mapEntry && i_mapEntry->Instanceable();
+}
+
+bool Map::IsDungeon() const
+{
+ return i_mapEntry && i_mapEntry->IsDungeon();
+}
+
+bool Map::IsNonRaidDungeon() const
+{
+ return i_mapEntry && i_mapEntry->IsNonRaidDungeon();
+}
+
+bool Map::IsRaid() const
+{
+ return i_mapEntry && i_mapEntry->IsRaid();
+}
+
+bool Map::IsRaidOrHeroicDungeon() const
+{
+ return IsRaid() || i_spawnMode > DUNGEON_DIFFICULTY_NORMAL;
+}
+
+bool Map::IsHeroic() const
+{
+ return IsRaid() ? i_spawnMode >= RAID_DIFFICULTY_10MAN_HEROIC : i_spawnMode >= DUNGEON_DIFFICULTY_HEROIC;
+}
+
+bool Map::Is25ManRaid() const
+{
+ // since 25man difficulties are 1 and 3, we can check them like that
+ return IsRaid() && i_spawnMode & RAID_DIFFICULTY_MASK_25MAN;
+}
+
+bool Map::IsBattleground() const
+{
+ return i_mapEntry && i_mapEntry->IsBattleground();
+}
+
+bool Map::IsBattleArena() const
+{
+ return i_mapEntry && i_mapEntry->IsBattleArena();
+}
+
+bool Map::IsBattlegroundOrArena() const
+{
+ return i_mapEntry && i_mapEntry->IsBattlegroundOrArena();
+}
+
+bool Map::GetEntrancePos(int32& mapid, float& x, float& y) const
+{
+ if (!i_mapEntry)
+ return false;
+ return i_mapEntry->GetEntrancePos(mapid, x, y);
+}
+
bool InstanceMap::HasPermBoundPlayers() const
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_PERM_BIND_BY_INSTANCE);
@@ -3526,7 +3605,7 @@ uint32 InstanceMap::GetMaxResetDelay() const
/* ******* Battleground Instance Maps ******* */
BattlegroundMap::BattlegroundMap(uint32 id, time_t expiry, uint32 InstanceId, Map* _parent, uint8 spawnMode)
- : Map(id, expiry, InstanceId, spawnMode, _parent), m_bg(NULL)
+ : Map(id, expiry, InstanceId, spawnMode, _parent), m_bg(nullptr)
{
//lets initialize visibility distance for BG/Arenas
BattlegroundMap::InitVisibilityDistance();
@@ -3537,8 +3616,8 @@ BattlegroundMap::~BattlegroundMap()
if (m_bg)
{
//unlink to prevent crash, always unlink all pointer reference before destruction
- m_bg->SetBgMap(NULL);
- m_bg = NULL;
+ m_bg->SetBgMap(nullptr);
+ m_bg = nullptr;
}
}
@@ -3627,10 +3706,10 @@ Pet* Map::GetPet(ObjectGuid const& guid)
Transport* Map::GetTransport(ObjectGuid const& guid)
{
if (!guid.IsMOTransport())
- return NULL;
+ return nullptr;
GameObject* go = GetGameObject(guid);
- return go ? go->ToTransport() : NULL;
+ return go ? go->ToTransport() : nullptr;
}
DynamicObject* Map::GetDynamicObject(ObjectGuid const& guid)
@@ -3863,7 +3942,7 @@ Corpse* Map::ConvertCorpseToBones(ObjectGuid const& ownerGuid, bool insignia /*=
corpse->DeleteFromDB(trans);
CharacterDatabase.CommitTransaction(trans);
- Corpse* bones = NULL;
+ Corpse* bones = nullptr;
// create the bones only if the map and the grid is loaded at the corpse's location
// ignore bones creating option in case insignia
@@ -4032,10 +4111,14 @@ void Map::UpdateAreaDependentAuras()
{
Map::PlayerList const& players = GetPlayers();
for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr)
+ {
if (Player* player = itr->GetSource())
+ {
if (player->IsInWorld())
{
player->UpdateAreaDependentAuras(player->GetAreaId());
player->UpdateZoneDependentAuras(player->GetZoneId());
}
+ }
+ }
}
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index 1a61e65bade..dd0e43158c1 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -21,7 +21,6 @@
#include "Define.h"
-#include "DBCStructure.h"
#include "GridDefines.h"
#include "Cell.h"
#include "Timer.h"
@@ -29,31 +28,37 @@
#include "GridRefManager.h"
#include "MapRefManager.h"
#include "DynamicTree.h"
-#include "GameObjectModel.h"
#include "ObjectGuid.h"
+#include "Optional.h"
#include <bitset>
#include <list>
#include <memory>
+#include <mutex>
-class Unit;
-class WorldPacket;
-class InstanceScript;
+class Battleground;
+class BattlegroundMap;
+class CreatureGroup;
+class GameObjectModel;
class Group;
+class InstanceMap;
class InstanceSave;
+class InstanceScript;
+class MapInstanced;
class Object;
-class WorldObject;
-class TempSummon;
class Player;
-class CreatureGroup;
-struct ScriptInfo;
-struct ScriptAction;
-struct Position;
-class Battleground;
-class MapInstanced;
-class BattlegroundMap;
-class InstanceMap;
+class TempSummon;
class Transport;
+class Unit;
+class WorldObject;
+class WorldPacket;
+struct MapDifficulty;
+struct MapEntry;
+struct Position;
+struct ScriptAction;
+struct ScriptInfo;
+struct SummonPropertiesEntry;
+enum Difficulty : uint8;
namespace Trinity { struct ObjectUpdater; }
namespace VMAP { enum class ModelIgnoreFlags : uint32; }
@@ -127,7 +132,7 @@ struct map_liquidHeader
float liquidLevel;
};
-enum ZLiquidStatus
+enum ZLiquidStatus : uint32
{
LIQUID_MAP_NO_WATER = 0x00000000,
LIQUID_MAP_ABOVE_WATER = 0x00000001,
@@ -176,14 +181,6 @@ struct PositionFullTerrainStatus
Optional<LiquidData> liquidInfo;
};
-enum LineOfSightChecks
-{
- LINEOFSIGHT_CHECK_VMAP = 0x1, // check static floor layout data
- LINEOFSIGHT_CHECK_GOBJECT = 0x2, // check dynamic game object data
-
- LINEOFSIGHT_ALL_CHECKS = (LINEOFSIGHT_CHECK_VMAP | LINEOFSIGHT_CHECK_GOBJECT)
-};
-
class TC_GAME_API GridMap
{
uint32 _flags;
@@ -234,7 +231,7 @@ class TC_GAME_API GridMap
public:
GridMap();
~GridMap();
- bool loadData(const char* filename);
+ bool loadData(char const* filename);
void unloadData();
uint16 getArea(float x, float y) const;
@@ -247,13 +244,6 @@ public:
#pragma pack(push, 1)
-struct InstanceTemplate
-{
- uint32 Parent;
- uint32 ScriptId;
- bool AllowMount;
-};
-
enum LevelRequirementVsMode
{
LEVELREQUIREMENT_HEROIC = 70
@@ -287,7 +277,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
{
friend class MapReference;
public:
- Map(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map* _parent = NULL);
+ Map(uint32 id, time_t, uint32 InstanceId, uint8 SpawnMode, Map* _parent = nullptr);
virtual ~Map();
MapEntry const* GetEntry() const { return i_mapEntry; }
@@ -312,7 +302,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
template<class T> void RemoveFromMap(T *, bool);
void VisitNearbyCellsOf(WorldObject* obj, TypeContainerVisitor<Trinity::ObjectUpdater, GridTypeMapContainer> &gridVisitor, TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer> &worldVisitor);
- virtual void Update(const uint32);
+ virtual void Update(uint32);
float GetVisibilityRange() const { return m_VisibleDistance; }
//function for setting up visibility distance for maps on per-type/per-Id basis
@@ -324,7 +314,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void DynamicObjectRelocation(DynamicObject* go, float x, float y, float z, float orientation);
template<class T, class CONTAINER>
- void Visit(const Cell& cell, TypeContainerVisitor<T, CONTAINER> &visitor);
+ void Visit(Cell const& cell, TypeContainerVisitor<T, CONTAINER>& visitor);
bool IsRemovalGrid(float x, float y) const
{
@@ -337,8 +327,8 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
return IsGridLoaded(Trinity::ComputeGridCoord(x, y));
}
- bool GetUnloadLock(const GridCoord &p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); }
- void SetUnloadLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); }
+ bool GetUnloadLock(GridCoord const& p) const { return getNGrid(p.x_coord, p.y_coord)->getUnloadLock(); }
+ void SetUnloadLock(GridCoord const& p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadExplicitLock(on); }
void LoadGrid(float x, float y);
void LoadAllCells();
bool UnloadGrid(NGridType& ngrid, bool pForce);
@@ -350,7 +340,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
}
time_t GetGridExpiry(void) const { return i_gridExpiry; }
- uint32 GetId(void) const { return i_mapEntry->MapID; }
+ uint32 GetId() const;
static bool ExistMap(uint32 mapid, int gx, int gy);
static bool ExistVMap(uint32 mapid, int gx, int gy);
@@ -412,33 +402,28 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
CANNOT_ENTER_UNSPECIFIED_REASON
};
virtual EnterState CannotEnter(Player* /*player*/) { return CAN_ENTER; }
- const char* GetMapName() const;
+ char const* GetMapName() const;
// have meaning only for instanced map (that have set real difficulty)
Difficulty GetDifficulty() const { return Difficulty(GetSpawnMode()); }
- bool IsRegularDifficulty() const { return GetDifficulty() == REGULAR_DIFFICULTY; }
+ bool IsRegularDifficulty() const;
MapDifficulty const* GetMapDifficulty() const;
- bool Instanceable() const { return i_mapEntry && i_mapEntry->Instanceable(); }
- bool IsDungeon() const { return i_mapEntry && i_mapEntry->IsDungeon(); }
- bool IsNonRaidDungeon() const { return i_mapEntry && i_mapEntry->IsNonRaidDungeon(); }
- bool IsRaid() const { return i_mapEntry && i_mapEntry->IsRaid(); }
- bool IsRaidOrHeroicDungeon() const { return IsRaid() || i_spawnMode > DUNGEON_DIFFICULTY_NORMAL; }
- bool IsHeroic() const { return IsRaid() ? i_spawnMode >= RAID_DIFFICULTY_10MAN_HEROIC : i_spawnMode >= DUNGEON_DIFFICULTY_HEROIC; }
- bool Is25ManRaid() const { return IsRaid() && i_spawnMode & RAID_DIFFICULTY_MASK_25MAN; } // since 25man difficulties are 1 and 3, we can check them like that
- bool IsBattleground() const { return i_mapEntry && i_mapEntry->IsBattleground(); }
- bool IsBattleArena() const { return i_mapEntry && i_mapEntry->IsBattleArena(); }
- bool IsBattlegroundOrArena() const { return i_mapEntry && i_mapEntry->IsBattlegroundOrArena(); }
- bool GetEntrancePos(int32 &mapid, float &x, float &y)
- {
- if (!i_mapEntry)
- return false;
- return i_mapEntry->GetEntrancePos(mapid, x, y);
- }
+ bool Instanceable() const;
+ bool IsDungeon() const;
+ bool IsNonRaidDungeon() const;
+ bool IsRaid() const;
+ bool IsRaidOrHeroicDungeon() const;
+ bool IsHeroic() const;
+ bool Is25ManRaid() const;
+ bool IsBattleground() const;
+ bool IsBattleArena() const;
+ bool IsBattlegroundOrArena() const;
+ bool GetEntrancePos(int32& mapid, float& x, float& y) const;
void AddObjectToRemoveList(WorldObject* obj);
void AddObjectToSwitchList(WorldObject* obj, bool on);
- virtual void DelayedUpdate(const uint32 diff);
+ virtual void DelayedUpdate(uint32 diff);
void resetMarkedCells() { marked_cells.reset(); }
bool isCellMarked(uint32 pCellId) { return marked_cells.test(pCellId); }
@@ -509,22 +494,22 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
return nullptr;
}
- MapInstanced* ToMapInstanced() { if (Instanceable()) return reinterpret_cast<MapInstanced*>(this); return NULL; }
- MapInstanced const* ToMapInstanced() const { if (Instanceable()) return reinterpret_cast<MapInstanced const*>(this); return NULL; }
+ MapInstanced* ToMapInstanced() { if (Instanceable()) return reinterpret_cast<MapInstanced*>(this); return nullptr; }
+ MapInstanced const* ToMapInstanced() const { if (Instanceable()) return reinterpret_cast<MapInstanced const*>(this); return nullptr; }
- InstanceMap* ToInstanceMap() { if (IsDungeon()) return reinterpret_cast<InstanceMap*>(this); else return NULL; }
- InstanceMap const* ToInstanceMap() const { if (IsDungeon()) return reinterpret_cast<InstanceMap const*>(this); return NULL; }
+ InstanceMap* ToInstanceMap() { if (IsDungeon()) return reinterpret_cast<InstanceMap*>(this); else return nullptr; }
+ InstanceMap const* ToInstanceMap() const { if (IsDungeon()) return reinterpret_cast<InstanceMap const*>(this); return nullptr; }
- BattlegroundMap* ToBattlegroundMap() { if (IsBattlegroundOrArena()) return reinterpret_cast<BattlegroundMap*>(this); else return NULL; }
- BattlegroundMap const* ToBattlegroundMap() const { if (IsBattlegroundOrArena()) return reinterpret_cast<BattlegroundMap const*>(this); return NULL; }
+ BattlegroundMap* ToBattlegroundMap() { if (IsBattlegroundOrArena()) return reinterpret_cast<BattlegroundMap*>(this); else return nullptr; }
+ BattlegroundMap const* ToBattlegroundMap() const { if (IsBattlegroundOrArena()) return reinterpret_cast<BattlegroundMap const*>(this); return nullptr; }
- float GetWaterOrGroundLevel(uint32 phasemask, float x, float y, float z, float* ground = NULL, bool swim = false) const;
+ float GetWaterOrGroundLevel(uint32 phasemask, float x, float y, float z, float* ground = nullptr, bool swim = false) const;
float GetHeight(uint32 phasemask, float x, float y, float z, bool vmap = true, float maxSearchDist = DEFAULT_HEIGHT_SEARCH) const;
bool isInLineOfSight(float x1, float y1, float z1, float x2, float y2, float z2, uint32 phasemask, LineOfSightChecks checks, VMAP::ModelIgnoreFlags ignoreFlags) const;
void Balance() { _dynamicTree.balance(); }
- void RemoveGameObjectModel(const GameObjectModel& model) { _dynamicTree.remove(model); }
- void InsertGameObjectModel(const GameObjectModel& model) { _dynamicTree.insert(model); }
- bool ContainsGameObjectModel(const GameObjectModel& model) const { return _dynamicTree.contains(model);}
+ void RemoveGameObjectModel(GameObjectModel const& model) { _dynamicTree.remove(model); }
+ void InsertGameObjectModel(GameObjectModel const& model) { _dynamicTree.insert(model); }
+ bool ContainsGameObjectModel(GameObjectModel const& model) const { return _dynamicTree.contains(model);}
float GetGameObjectFloor(uint32 phasemask, float x, float y, float z, float maxSearchDist = DEFAULT_HEIGHT_SEARCH) const
{
return _dynamicTree.getHeight(x, y, z, maxSearchDist, phasemask);
@@ -636,9 +621,9 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
bool _dynamicObjectsToMoveLock;
std::vector<DynamicObject*> _dynamicObjectsToMove;
- bool IsGridLoaded(const GridCoord &) const;
- void EnsureGridCreated(const GridCoord &);
- void EnsureGridCreated_i(const GridCoord &);
+ bool IsGridLoaded(GridCoord const&) const;
+ void EnsureGridCreated(GridCoord const&);
+ void EnsureGridCreated_i(GridCoord const&);
bool EnsureGridLoaded(Cell const&);
void EnsureGridLoadedForActiveObject(Cell const&, WorldObject* object);
@@ -656,12 +641,10 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
void setNGrid(NGridType* grid, uint32 x, uint32 y);
void ScriptsProcess();
- void UpdateActiveCells(const float &x, const float &y, const uint32 t_diff);
-
void SendObjectUpdates();
protected:
- void SetUnloadReferenceLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
+ void SetUnloadReferenceLock(GridCoord const& p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
std::mutex _mapLock;
std::mutex _gridLock;
@@ -688,13 +671,13 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
TransportsContainer::iterator _transportsUpdateIter;
private:
- Player* _GetScriptPlayerSourceOrTarget(Object* source, Object* target, const ScriptInfo* scriptInfo) const;
- Creature* _GetScriptCreatureSourceOrTarget(Object* source, Object* target, const ScriptInfo* scriptInfo, bool bReverse = false) const;
- Unit* _GetScriptUnit(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const;
- Player* _GetScriptPlayer(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const;
- Creature* _GetScriptCreature(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const;
- WorldObject* _GetScriptWorldObject(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const;
- void _ScriptProcessDoor(Object* source, Object* target, const ScriptInfo* scriptInfo) const;
+ Player* _GetScriptPlayerSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo) const;
+ Creature* _GetScriptCreatureSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo, bool bReverse = false) const;
+ Unit* _GetScriptUnit(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const;
+ Player* _GetScriptPlayer(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const;
+ Creature* _GetScriptCreature(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const;
+ WorldObject* _GetScriptWorldObject(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const;
+ void _ScriptProcessDoor(Object* source, Object* target, ScriptInfo const* scriptInfo) const;
GameObject* _FindGameObject(WorldObject* pWorldObject, ObjectGuid::LowType guid) const;
time_t i_gridExpiry;
@@ -791,10 +774,11 @@ class TC_GAME_API InstanceMap : public Map
~InstanceMap();
bool AddPlayerToMap(Player*) override;
void RemovePlayerFromMap(Player*, bool) override;
- void Update(const uint32) override;
+ void Update(uint32) override;
void CreateInstanceData(bool load);
bool Reset(uint8 method);
uint32 GetScriptId() const { return i_script_id; }
+ std::string const& GetScriptName() const;
InstanceScript* GetInstanceScript() { return i_data; }
InstanceScript const* GetInstanceScript() const { return i_data; }
void PermBindAllPlayers();
diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp
index d54e758e581..4b8863889a1 100644
--- a/src/server/game/Maps/MapInstanced.cpp
+++ b/src/server/game/Maps/MapInstanced.cpp
@@ -17,15 +17,17 @@
*/
#include "MapInstanced.h"
-#include "ObjectMgr.h"
-#include "MapManager.h"
#include "Battleground.h"
-#include "VMapFactory.h"
-#include "MMapFactory.h"
-#include "InstanceSaveMgr.h"
-#include "World.h"
+#include "DBCStores.h"
#include "Group.h"
+#include "InstanceSaveMgr.h"
+#include "Log.h"
+#include "MapManager.h"
+#include "MMapFactory.h"
+#include "ObjectMgr.h"
#include "Player.h"
+#include "VMapFactory.h"
+#include "World.h"
MapInstanced::MapInstanced(uint32 id, time_t expiry) : Map(id, expiry, 0, DUNGEON_DIFFICULTY_NORMAL)
{
@@ -44,7 +46,7 @@ void MapInstanced::InitVisibilityDistance()
}
}
-void MapInstanced::Update(const uint32 t)
+void MapInstanced::Update(uint32 t)
{
// take care of loaded GridMaps (when unused, unload it!)
Map::Update(t);
@@ -73,7 +75,7 @@ void MapInstanced::Update(const uint32 t)
}
}
-void MapInstanced::DelayedUpdate(const uint32 diff)
+void MapInstanced::DelayedUpdate(uint32 diff)
{
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
i->second->DelayedUpdate(diff);
@@ -110,7 +112,7 @@ void MapInstanced::UnloadAll()
- create the instance if it's not created already
- the player is not actually added to the instance (only in InstanceMap::Add)
*/
-Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player, uint32 loginInstanceId)
+Map* MapInstanced::CreateInstanceForPlayer(uint32 mapId, Player* player, uint32 loginInstanceId /*= 0*/)
{
if (GetId() != mapId || !player)
return nullptr;
@@ -190,7 +192,7 @@ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player, u
//ASSERT(!FindInstanceMap(NewInstanceId));
map = FindInstanceMap(newInstanceId);
if (!map)
- map = CreateInstance(newInstanceId, NULL, diff);
+ map = CreateInstance(newInstanceId, nullptr, diff);
}
}
@@ -203,13 +205,13 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
std::lock_guard<std::mutex> lock(_mapLock);
// make sure we have a valid map id
- const MapEntry* entry = sMapStore.LookupEntry(GetId());
+ MapEntry const* entry = sMapStore.LookupEntry(GetId());
if (!entry)
{
TC_LOG_ERROR("maps", "CreateInstance: no entry for map %d", GetId());
ABORT();
}
- const InstanceTemplate* iTemplate = sObjectMgr->GetInstanceTemplate(GetId());
+ InstanceTemplate const* iTemplate = sObjectMgr->GetInstanceTemplate(GetId());
if (!iTemplate)
{
TC_LOG_ERROR("maps", "CreateInstance: no instance template for map %d", GetId());
@@ -227,7 +229,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
map->LoadRespawnTimes();
map->LoadCorpseData();
- bool load_data = save != NULL;
+ bool load_data = save != nullptr;
map->CreateInstanceData(load_data);
if (sWorld->getBoolConfig(CONFIG_INSTANCEMAP_LOAD_GRIDS))
diff --git a/src/server/game/Maps/MapInstanced.h b/src/server/game/Maps/MapInstanced.h
index 2394aa2035a..7f4184fca3b 100644
--- a/src/server/game/Maps/MapInstanced.h
+++ b/src/server/game/Maps/MapInstanced.h
@@ -33,13 +33,13 @@ class TC_GAME_API MapInstanced : public Map
~MapInstanced() { }
// functions overwrite Map versions
- void Update(const uint32) override;
- void DelayedUpdate(const uint32 diff) override;
+ void Update(uint32 diff) override;
+ void DelayedUpdate(uint32 diff) override;
//void RelocationNotify();
void UnloadAll() override;
EnterState CannotEnter(Player* /*player*/) override;
- Map* CreateInstanceForPlayer(const uint32 mapId, Player* player, uint32 loginInstanceId=0);
+ Map* CreateInstanceForPlayer(uint32 mapId, Player* player, uint32 loginInstanceId = 0);
Map* FindInstanceMap(uint32 instanceId) const
{
InstancedMaps::const_iterator i = m_InstancedMaps.find(instanceId);
@@ -47,7 +47,7 @@ class TC_GAME_API MapInstanced : public Map
}
bool DestroyInstance(InstancedMaps::iterator &itr);
- void AddGridMapReference(const GridCoord &p)
+ void AddGridMapReference(GridCoord const& p)
{
++GridMapReference[p.x_coord][p.y_coord];
SetUnloadReferenceLock(GridCoord((MAX_NUMBER_OF_GRIDS - 1) - p.x_coord, (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord), true);
diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp
index a0317013d3e..8026f944c2a 100644
--- a/src/server/game/Maps/MapManager.cpp
+++ b/src/server/game/Maps/MapManager.cpp
@@ -57,7 +57,7 @@ void MapManager::Initialize()
void MapManager::InitializeVisibilityDistanceInfo()
{
- for (MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
+ for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter)
(*iter).second->InitVisibilityDistance();
}
@@ -71,7 +71,7 @@ Map* MapManager::CreateBaseMap(uint32 id)
{
Map* map = FindBaseMap(id);
- if (map == NULL)
+ if (map == nullptr)
{
std::lock_guard<std::mutex> lock(_mapsLock);
@@ -98,7 +98,7 @@ Map* MapManager::FindBaseNonInstanceMap(uint32 mapId) const
{
Map* map = FindBaseMap(mapId);
if (map && map->Instanceable())
- return NULL;
+ return nullptr;
return map;
}
@@ -116,10 +116,10 @@ Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const
{
Map* map = FindBaseMap(mapid);
if (!map)
- return NULL;
+ return nullptr;
if (!map->Instanceable())
- return instanceId == 0 ? map : NULL;
+ return instanceId == 0 ? map : nullptr;
return ((MapInstanced*)map)->FindInstanceMap(instanceId);
}
diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h
index 0882efd1e31..e628a7030ae 100644
--- a/src/server/game/Maps/MapManager.h
+++ b/src/server/game/Maps/MapManager.h
@@ -75,7 +75,7 @@ class TC_GAME_API MapManager
i_timer.Reset();
}
- //void LoadGrid(int mapid, int instId, float x, float y, const WorldObject* obj, bool no_unload = false);
+ //void LoadGrid(int mapid, int instId, float x, float y, WorldObject const* obj, bool no_unload = false);
void UnloadAll();
static bool ExistMapAndVMap(uint32 mapid, float x, float y);
@@ -139,11 +139,11 @@ class TC_GAME_API MapManager
Map* FindBaseMap(uint32 mapId) const
{
MapMapType::const_iterator iter = i_maps.find(mapId);
- return (iter == i_maps.end() ? NULL : iter->second);
+ return (iter == i_maps.end() ? nullptr : iter->second);
}
- MapManager(const MapManager &);
- MapManager& operator=(const MapManager &);
+ MapManager(MapManager const&) = delete;
+ MapManager& operator=(MapManager const&) = delete;
std::mutex _mapsLock;
uint32 i_gridCleanUpDelay;
diff --git a/src/server/game/Maps/MapObject.h b/src/server/game/Maps/MapObject.h
new file mode 100644
index 00000000000..22e920994c8
--- /dev/null
+++ b/src/server/game/Maps/MapObject.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MapObject_h__
+#define MapObject_h__
+
+#include "Define.h"
+#include "Cell.h"
+#include "Position.h"
+
+class Map;
+class ObjectGridLoader;
+
+enum MapObjectCellMoveState
+{
+ MAP_OBJECT_CELL_MOVE_NONE, //not in move list
+ MAP_OBJECT_CELL_MOVE_ACTIVE, //in move list
+ MAP_OBJECT_CELL_MOVE_INACTIVE, //in move list but should not move
+};
+
+class TC_GAME_API MapObject
+{
+ friend class Map; //map for moving creatures
+ friend class ObjectGridLoader; //grid loader for loading creatures
+
+protected:
+ MapObject() : _moveState(MAP_OBJECT_CELL_MOVE_NONE)
+ {
+ _newPosition.Relocate(0.0f, 0.0f, 0.0f, 0.0f);
+ }
+
+private:
+ Cell _currentCell;
+ Cell const& GetCurrentCell() const { return _currentCell; }
+ void SetCurrentCell(Cell const& cell) { _currentCell = cell; }
+
+ MapObjectCellMoveState _moveState;
+ Position _newPosition;
+ void SetNewCellPosition(float x, float y, float z, float o)
+ {
+ _moveState = MAP_OBJECT_CELL_MOVE_ACTIVE;
+ _newPosition.Relocate(x, y, z, o);
+ }
+};
+
+#endif // MapObject_h__
diff --git a/src/server/game/Maps/MapReference.cpp b/src/server/game/Maps/MapReference.cpp
new file mode 100644
index 00000000000..ca8169129e2
--- /dev/null
+++ b/src/server/game/Maps/MapReference.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "MapReference.h"
+#include "Map.h"
+
+void MapReference::targetObjectBuildLink()
+{
+ // called from link()
+ getTarget()->m_mapRefManager.insertFirst(this);
+ getTarget()->m_mapRefManager.incSize();
+}
+
+void MapReference::targetObjectDestroyLink()
+{
+ // called from unlink()
+ if (isValid())
+ getTarget()->m_mapRefManager.decSize();
+}
+
+void MapReference::sourceObjectDestroyLink()
+{
+ // called from invalidate()
+ getTarget()->m_mapRefManager.decSize();
+}
diff --git a/src/server/game/Maps/MapReference.h b/src/server/game/Maps/MapReference.h
index 11a97b6f44b..73b0635390e 100644
--- a/src/server/game/Maps/MapReference.h
+++ b/src/server/game/Maps/MapReference.h
@@ -20,27 +20,16 @@
#define _MAPREFERENCE_H
#include "Reference.h"
-#include "Map.h"
+
+class Map;
+class Player;
class MapReference : public Reference<Map, Player>
{
protected:
- void targetObjectBuildLink() override
- {
- // called from link()
- getTarget()->m_mapRefManager.insertFirst(this);
- getTarget()->m_mapRefManager.incSize();
- }
- void targetObjectDestroyLink() override
- {
- // called from unlink()
- if (isValid()) getTarget()->m_mapRefManager.decSize();
- }
- void sourceObjectDestroyLink() override
- {
- // called from invalidate()
- getTarget()->m_mapRefManager.decSize();
- }
+ void targetObjectBuildLink() override;
+ void targetObjectDestroyLink() override;
+ void sourceObjectDestroyLink() override;
public:
MapReference() : Reference<Map, Player>() { }
~MapReference() { unlink(); }
diff --git a/src/server/game/Maps/MapScripts.cpp b/src/server/game/Maps/MapScripts.cpp
index f5c8cd971b9..e365a54c594 100644
--- a/src/server/game/Maps/MapScripts.cpp
+++ b/src/server/game/Maps/MapScripts.cpp
@@ -16,17 +16,17 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "Map.h"
#include "CellImpl.h"
#include "GameTime.h"
-#include "GridNotifiers.h"
-#include "GridNotifiersImpl.h"
#include "GossipDef.h"
-#include "Map.h"
+#include "GridNotifiers.h"
+#include "Item.h"
+#include "Log.h"
#include "MapManager.h"
+#include "MotionMaster.h"
#include "ObjectMgr.h"
#include "Pet.h"
-#include "Item.h"
-#include "ScriptedCreature.h"
#include "ScriptMgr.h"
#include "Transport.h"
#include "WaypointManager.h"
@@ -100,9 +100,9 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou
}
// Helpers for ScriptProcess method.
-inline Player* Map::_GetScriptPlayerSourceOrTarget(Object* source, Object* target, const ScriptInfo* scriptInfo) const
+inline Player* Map::_GetScriptPlayerSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo) const
{
- Player* player = NULL;
+ Player* player = nullptr;
if (!source && !target)
TC_LOG_ERROR("scripts", "%s source and target objects are NULL.", scriptInfo->GetDebugInfo().c_str());
else
@@ -122,9 +122,9 @@ inline Player* Map::_GetScriptPlayerSourceOrTarget(Object* source, Object* targe
return player;
}
-inline Creature* Map::_GetScriptCreatureSourceOrTarget(Object* source, Object* target, const ScriptInfo* scriptInfo, bool bReverse) const
+inline Creature* Map::_GetScriptCreatureSourceOrTarget(Object* source, Object* target, ScriptInfo const* scriptInfo, bool bReverse) const
{
- Creature* creature = NULL;
+ Creature* creature = nullptr;
if (!source && !target)
TC_LOG_ERROR("scripts", "%s source and target objects are NULL.", scriptInfo->GetDebugInfo().c_str());
else
@@ -155,9 +155,9 @@ inline Creature* Map::_GetScriptCreatureSourceOrTarget(Object* source, Object* t
return creature;
}
-inline Unit* Map::_GetScriptUnit(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const
+inline Unit* Map::_GetScriptUnit(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const
{
- Unit* unit = NULL;
+ Unit* unit = nullptr;
if (!obj)
TC_LOG_ERROR("scripts", "%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
else if (!obj->isType(TYPEMASK_UNIT))
@@ -173,9 +173,9 @@ inline Unit* Map::_GetScriptUnit(Object* obj, bool isSource, const ScriptInfo* s
return unit;
}
-inline Player* Map::_GetScriptPlayer(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const
+inline Player* Map::_GetScriptPlayer(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const
{
- Player* player = NULL;
+ Player* player = nullptr;
if (!obj)
TC_LOG_ERROR("scripts", "%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
else
@@ -188,9 +188,9 @@ inline Player* Map::_GetScriptPlayer(Object* obj, bool isSource, const ScriptInf
return player;
}
-inline Creature* Map::_GetScriptCreature(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const
+inline Creature* Map::_GetScriptCreature(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const
{
- Creature* creature = NULL;
+ Creature* creature = nullptr;
if (!obj)
TC_LOG_ERROR("scripts", "%s %s object is NULL.", scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
else
@@ -203,9 +203,9 @@ inline Creature* Map::_GetScriptCreature(Object* obj, bool isSource, const Scrip
return creature;
}
-inline WorldObject* Map::_GetScriptWorldObject(Object* obj, bool isSource, const ScriptInfo* scriptInfo) const
+inline WorldObject* Map::_GetScriptWorldObject(Object* obj, bool isSource, ScriptInfo const* scriptInfo) const
{
- WorldObject* pWorldObject = NULL;
+ WorldObject* pWorldObject = nullptr;
if (!obj)
TC_LOG_ERROR("scripts", "%s %s object is NULL.",
scriptInfo->GetDebugInfo().c_str(), isSource ? "source" : "target");
@@ -219,7 +219,7 @@ inline WorldObject* Map::_GetScriptWorldObject(Object* obj, bool isSource, const
return pWorldObject;
}
-inline void Map::_ScriptProcessDoor(Object* source, Object* target, const ScriptInfo* scriptInfo) const
+inline void Map::_ScriptProcessDoor(Object* source, Object* target, ScriptInfo const* scriptInfo) const
{
bool bOpen = false;
ObjectGuid::LowType guid = scriptInfo->ToggleDoor.GOGuid;
@@ -290,7 +290,7 @@ void Map::ScriptsProcess()
{
ScriptAction const& step = iter->second;
- Object* source = NULL;
+ Object* source = nullptr;
if (step.sourceGUID)
{
switch (step.sourceGUID.GetHigh())
@@ -326,7 +326,7 @@ void Map::ScriptsProcess()
}
}
- WorldObject* target = NULL;
+ WorldObject* target = nullptr;
if (step.targetGUID)
{
switch (step.targetGUID.GetHigh())
@@ -669,30 +669,30 @@ void Map::ScriptsProcess()
break;
}
- Unit* uSource = NULL;
- Unit* uTarget = NULL;
+ Unit* uSource = nullptr;
+ Unit* uTarget = nullptr;
// source/target cast spell at target/source (script->datalong2: 0: s->t 1: s->s 2: t->t 3: t->s
switch (step.script->CastSpell.Flags)
{
case SF_CASTSPELL_SOURCE_TO_TARGET: // source -> target
- uSource = source ? source->ToUnit() : NULL;
- uTarget = target ? target->ToUnit() : NULL;
+ uSource = source ? source->ToUnit() : nullptr;
+ uTarget = target ? target->ToUnit() : nullptr;
break;
case SF_CASTSPELL_SOURCE_TO_SOURCE: // source -> source
- uSource = source ? source->ToUnit() : NULL;
+ uSource = source ? source->ToUnit() : nullptr;
uTarget = uSource;
break;
case SF_CASTSPELL_TARGET_TO_TARGET: // target -> target
- uSource = target ? target->ToUnit() : NULL;
+ uSource = target ? target->ToUnit() : nullptr;
uTarget = uSource;
break;
case SF_CASTSPELL_TARGET_TO_SOURCE: // target -> source
- uSource = target ? target->ToUnit() : NULL;
- uTarget = source ? source->ToUnit() : NULL;
+ uSource = target ? target->ToUnit() : nullptr;
+ uTarget = source ? source->ToUnit() : nullptr;
break;
case SF_CASTSPELL_SEARCH_CREATURE: // source -> creature with entry
- uSource = source ? source->ToUnit() : NULL;
- uTarget = uSource ? GetClosestCreatureWithEntry(uSource, abs(step.script->CastSpell.CreatureEntry), step.script->CastSpell.SearchRadius) : NULL;
+ uSource = source ? source->ToUnit() : nullptr;
+ uTarget = uSource ? uSource->FindNearestCreature(abs(step.script->CastSpell.CreatureEntry), step.script->CastSpell.SearchRadius) : nullptr;
break;
}
@@ -720,7 +720,7 @@ void Map::ScriptsProcess()
if (WorldObject* object = _GetScriptWorldObject(source, true, step.script))
{
// PlaySound.Flags bitmask: 0/1=anyone/target
- Player* player = NULL;
+ Player* player = nullptr;
if (step.script->PlaySound.Flags & SF_PLAYSOUND_TARGET_PLAYER)
{
// Target must be Player.
@@ -749,7 +749,7 @@ void Map::ScriptsProcess()
pReceiver->SendNewItem(item, step.script->CreateItem.Amount, false, true);
}
else
- pReceiver->SendEquipError(msg, NULL, NULL, step.script->CreateItem.ItemEntry);
+ pReceiver->SendEquipError(msg, nullptr, nullptr, step.script->CreateItem.ItemEntry);
}
break;
@@ -783,7 +783,7 @@ void Map::ScriptsProcess()
break;
}
- Creature* cTarget = NULL;
+ Creature* cTarget = nullptr;
auto creatureBounds = _creatureBySpawnIdStore.equal_range(step.script->CallScript.CreatureEntry);
if (creatureBounds.first != creatureBounds.second)
{
@@ -811,7 +811,7 @@ void Map::ScriptsProcess()
}
// Insert script into schedule but do not start it
- ScriptsStart(*datamap, step.script->CallScript.ScriptID, cTarget, NULL);
+ ScriptsStart(*datamap, step.script->CallScript.ScriptID, cTarget, nullptr);
break;
}
diff --git a/src/server/game/Maps/TransportMgr.cpp b/src/server/game/Maps/TransportMgr.cpp
index 3eb09166ac9..b6bcfde3723 100644
--- a/src/server/game/Maps/TransportMgr.cpp
+++ b/src/server/game/Maps/TransportMgr.cpp
@@ -16,20 +16,18 @@
*/
#include "TransportMgr.h"
-#include "Transport.h"
+#include "DatabaseEnv.h"
#include "InstanceScript.h"
-#include "MoveSpline.h"
+#include "Log.h"
#include "MapManager.h"
+#include "MoveSplineInitArgs.h"
+#include "ObjectAccessor.h"
+#include "ObjectMgr.h"
+#include "Spline.h"
+#include "Transport.h"
TransportTemplate::~TransportTemplate()
{
- // Collect shared pointers into a set to avoid deleting the same memory more than once
- std::set<TransportSpline*> splines;
- for (size_t i = 0; i < keyFrames.size(); ++i)
- splines.insert(keyFrames[i].Spline);
-
- for (std::set<TransportSpline*>::iterator itr = splines.begin(); itr != splines.end(); ++itr)
- delete *itr;
}
TransportMgr::TransportMgr() { }
@@ -66,7 +64,7 @@ void TransportMgr::LoadTransportTemplates()
Field* fields = result->Fetch();
uint32 entry = fields[0].GetUInt32();
GameObjectTemplate const* goInfo = sObjectMgr->GetGameObjectTemplate(entry);
- if (goInfo == NULL)
+ if (goInfo == nullptr)
{
TC_LOG_ERROR("sql.sql", "Transport %u has no associated GameObjectTemplate from `gameobject_template` , skipped.", entry);
continue;
@@ -93,6 +91,17 @@ void TransportMgr::LoadTransportTemplates()
TC_LOG_INFO("server.loading", ">> Loaded %u transport templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
+void TransportMgr::LoadTransportAnimationAndRotation()
+{
+ for (uint32 i = 0; i < sTransportAnimationStore.GetNumRows(); ++i)
+ if (TransportAnimationEntry const* anim = sTransportAnimationStore.LookupEntry(i))
+ AddPathNodeToTransport(anim->TransportEntry, anim->TimeSeg, anim);
+
+ for (uint32 i = 0; i < sTransportRotationStore.GetNumRows(); ++i)
+ if (TransportRotationEntry const* rot = sTransportRotationStore.LookupEntry(i))
+ AddPathRotationToTransport(rot->TransportEntry, rot->TimeSeg, rot);
+}
+
class SplineRawInitializer
{
public:
@@ -213,7 +222,7 @@ void TransportMgr::GeneratePath(GameObjectTemplate const* goInfo, TransportTempl
if (keyFrames[i - 1].Teleport || i + 1 == keyFrames.size())
{
size_t extra = !keyFrames[i - 1].Teleport ? 1 : 0;
- TransportSpline* spline = new TransportSpline();
+ std::shared_ptr<TransportSpline> spline = std::make_shared<TransportSpline>();
spline->init_spline(&splinePath[start], i - start + extra, Movement::SplineBase::ModeCatmullrom);
spline->initLengths();
for (size_t j = start; j < i + extra; ++j)
@@ -354,7 +363,7 @@ void TransportMgr::AddPathNodeToTransport(uint32 transportEntry, uint32 timeSeg,
animNode.Path[timeSeg] = node;
}
-Transport* TransportMgr::CreateTransport(uint32 entry, ObjectGuid::LowType guid /*= 0*/, Map* map /*= NULL*/)
+Transport* TransportMgr::CreateTransport(uint32 entry, ObjectGuid::LowType guid /*= 0*/, Map* map /*= nullptr*/)
{
// instance case, execute GetGameObjectEntry hook
if (map)
@@ -365,14 +374,14 @@ Transport* TransportMgr::CreateTransport(uint32 entry, ObjectGuid::LowType guid
entry = instance->GetGameObjectEntry(0, entry);
if (!entry)
- return NULL;
+ return nullptr;
}
TransportTemplate const* tInfo = GetTransportTemplate(entry);
if (!tInfo)
{
TC_LOG_ERROR("sql.sql", "Transport %u will not be loaded, `transport_template` missing", entry);
- return NULL;
+ return nullptr;
}
// create transport...
@@ -392,7 +401,7 @@ Transport* TransportMgr::CreateTransport(uint32 entry, ObjectGuid::LowType guid
if (!trans->Create(guidLow, entry, mapId, x, y, z, o, 255))
{
delete trans;
- return NULL;
+ return nullptr;
}
if (MapEntry const* mapEntry = sMapStore.LookupEntry(mapId))
@@ -401,12 +410,12 @@ Transport* TransportMgr::CreateTransport(uint32 entry, ObjectGuid::LowType guid
{
TC_LOG_ERROR("entities.transport", "Transport %u (name: %s) attempted creation in instance map (id: %u) but it is not an instanced transport!", entry, trans->GetName().c_str(), mapId);
delete trans;
- return NULL;
+ return nullptr;
}
}
// use preset map for instances (need to know which instance)
- trans->SetMap(map ? map : sMapMgr->CreateMap(mapId, NULL));
+ trans->SetMap(map ? map : sMapMgr->CreateMap(mapId, nullptr));
if (map && map->IsDungeon())
trans->m_zoneScript = map->ToInstanceMap()->GetInstanceScript();
@@ -460,30 +469,18 @@ void TransportMgr::CreateInstanceTransports(Map* map)
TransportAnimationEntry const* TransportAnimation::GetAnimNode(uint32 time) const
{
- if (Path.empty())
- return NULL;
-
- for (TransportPathContainer::const_reverse_iterator itr2 = Path.rbegin(); itr2 != Path.rend(); ++itr2)
- if (time >= itr2->first)
- return itr2->second;
+ auto itr = Path.lower_bound(time);
+ if (itr != Path.end())
+ return itr->second;
- return Path.begin()->second;
+ return nullptr;
}
-G3D::Quat TransportAnimation::GetAnimRotation(uint32 time) const
+TransportRotationEntry const* TransportAnimation::GetAnimRotation(uint32 time) const
{
- if (Rotations.empty())
- return G3D::Quat(0.0f, 0.0f, 0.0f, 1.0f);
-
- TransportRotationEntry const* rot = Rotations.begin()->second;
- for (TransportPathRotationContainer::const_reverse_iterator itr2 = Rotations.rbegin(); itr2 != Rotations.rend(); ++itr2)
- {
- if (time >= itr2->first)
- {
- rot = itr2->second;
- break;
- }
- }
+ auto itr = Rotations.lower_bound(time);
+ if (itr != Rotations.end())
+ return itr->second;
- return G3D::Quat(rot->X, rot->Y, rot->Z, rot->W);
+ return nullptr;
}
diff --git a/src/server/game/Maps/TransportMgr.h b/src/server/game/Maps/TransportMgr.h
index abb86572766..86a38b3303a 100644
--- a/src/server/game/Maps/TransportMgr.h
+++ b/src/server/game/Maps/TransportMgr.h
@@ -18,10 +18,9 @@
#ifndef TRANSPORTMGR_H
#define TRANSPORTMGR_H
-#include <G3D/Quat.h>
-#include "Spline.h"
#include "DBCStores.h"
#include "ObjectGuid.h"
+#include <memory>
struct KeyFrame;
struct GameObjectTemplate;
@@ -29,6 +28,11 @@ struct TransportTemplate;
class Transport;
class Map;
+namespace Movement
+{
+ template <typename length_type> class Spline;
+}
+
typedef Movement::Spline<double> TransportSpline;
typedef std::vector<KeyFrame> KeyFrameVec;
typedef std::unordered_map<uint32, TransportTemplate> TransportTemplates;
@@ -40,7 +44,7 @@ struct KeyFrame
{
explicit KeyFrame(TaxiPathNodeEntry const* node) : Index(0), Node(node), InitialOrientation(0.0f),
DistSinceStop(-1.0f), DistUntilStop(-1.0f), DistFromPrev(-1.0f), TimeFrom(0.0f), TimeTo(0.0f),
- Teleport(false), ArriveTime(0), DepartureTime(0), Spline(NULL), NextDistFromPrev(0.0f), NextArriveTime(0)
+ Teleport(false), ArriveTime(0), DepartureTime(0), Spline(nullptr), NextDistFromPrev(0.0f), NextArriveTime(0)
{
}
@@ -55,7 +59,7 @@ struct KeyFrame
bool Teleport;
uint32 ArriveTime;
uint32 DepartureTime;
- TransportSpline* Spline;
+ std::shared_ptr<TransportSpline> Spline;
// Data needed for next frame
float NextDistFromPrev;
@@ -91,15 +95,13 @@ struct TC_GAME_API TransportAnimation
uint32 TotalTime;
TransportAnimationEntry const* GetAnimNode(uint32 time) const;
- G3D::Quat GetAnimRotation(uint32 time) const;
+ TransportRotationEntry const* GetAnimRotation(uint32 time) const;
};
typedef std::map<uint32, TransportAnimation> TransportAnimationContainer;
class TC_GAME_API TransportMgr
{
- friend TC_GAME_API void LoadDBCStores(std::string const&);
-
public:
static TransportMgr* instance();
@@ -107,8 +109,10 @@ class TC_GAME_API TransportMgr
void LoadTransportTemplates();
+ void LoadTransportAnimationAndRotation();
+
// Creates a transport using given GameObject template entry
- Transport* CreateTransport(uint32 entry, ObjectGuid::LowType guid = 0, Map* map = NULL);
+ Transport* CreateTransport(uint32 entry, ObjectGuid::LowType guid = 0, Map* map = nullptr);
// Spawns all continent transports, used at core startup
void SpawnContinentTransports();
@@ -121,7 +125,7 @@ class TC_GAME_API TransportMgr
TransportTemplates::const_iterator itr = _transportTemplates.find(entry);
if (itr != _transportTemplates.end())
return &itr->second;
- return NULL;
+ return nullptr;
}
TransportAnimation const* GetTransportAnimInfo(uint32 entry) const
@@ -130,14 +134,14 @@ class TC_GAME_API TransportMgr
if (itr != _transportAnimations.end())
return &itr->second;
- return NULL;
+ return nullptr;
}
private:
TransportMgr();
~TransportMgr();
- TransportMgr(TransportMgr const&);
- TransportMgr& operator=(TransportMgr const&);
+ TransportMgr(TransportMgr const&) = delete;
+ TransportMgr& operator=(TransportMgr const&) = delete;
// Generates and precaches a path for transport to avoid generation each time transport instance is created
void GeneratePath(GameObjectTemplate const* goInfo, TransportTemplate* transport);
diff --git a/src/server/game/Maps/ZoneScript.cpp b/src/server/game/Maps/ZoneScript.cpp
new file mode 100644
index 00000000000..e16007a34f3
--- /dev/null
+++ b/src/server/game/Maps/ZoneScript.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ZoneScript.h"
+#include "Creature.h"
+
+uint32 ZoneScript::GetCreatureEntry(ObjectGuid::LowType /*guidLow*/, CreatureData const* data)
+{
+ return data->id;
+}
diff --git a/src/server/game/Maps/ZoneScript.h b/src/server/game/Maps/ZoneScript.h
index 75fb56e555c..9c957022bc9 100644
--- a/src/server/game/Maps/ZoneScript.h
+++ b/src/server/game/Maps/ZoneScript.h
@@ -18,18 +18,22 @@
#ifndef ZONE_SCRIPT_H_
#define ZONE_SCRIPT_H_
-#include "Common.h"
-#include "Creature.h"
+#include "Define.h"
+#include "ObjectGuid.h"
+class Creature;
class GameObject;
+class Unit;
+class WorldObject;
+struct CreatureData;
-class ZoneScript
+class TC_GAME_API ZoneScript
{
public:
ZoneScript() { }
virtual ~ZoneScript() { }
- virtual uint32 GetCreatureEntry(ObjectGuid::LowType /*guidLow*/, CreatureData const* data) { return data->id; }
+ virtual uint32 GetCreatureEntry(ObjectGuid::LowType /*guidLow*/, CreatureData const* data);
virtual uint32 GetGameObjectEntry(ObjectGuid::LowType /*guidLow*/, uint32 entry) { return entry; }
virtual void OnCreatureCreate(Creature* ) { }