aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/framework/GameSystem/Grid.h9
-rw-r--r--src/game/Creature.cpp7
-rw-r--r--src/game/Map.cpp49
-rw-r--r--src/game/Map.h6
-rw-r--r--src/game/MapInstanced.cpp10
-rw-r--r--src/game/MapInstanced.h2
-rw-r--r--src/game/MapManager.cpp2
-rw-r--r--src/game/Object.cpp2
-rw-r--r--src/game/Unit.h1
9 files changed, 55 insertions, 33 deletions
diff --git a/src/framework/GameSystem/Grid.h b/src/framework/GameSystem/Grid.h
index a60b7306efb..fffa8120883 100644
--- a/src/framework/GameSystem/Grid.h
+++ b/src/framework/GameSystem/Grid.h
@@ -120,6 +120,15 @@ class TRINITY_DLL_DECL Grid
*/
template<class SPECIFIC_OBJECT> bool RemoveGridObject(SPECIFIC_OBJECT *obj, OBJECT_HANDLE hdl) { return i_container.template remove<SPECIFIC_OBJECT>(obj, hdl); }
+ bool NoWorldObjectInGrid() const
+ {
+ return i_objects.GetElements().isEmpty();
+ }
+
+ bool NoGridObjectInGrid() const
+ {
+ return i_container.GetElements().isEmpty();
+ }
private:
typedef typename ThreadModel::Lock Guard;
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index ece6ea3e527..e2a9fab0998 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1662,7 +1662,8 @@ void Creature::setDeathState(DeathState s)
{
SetUInt64Value (UNIT_FIELD_TARGET,0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
SetUInt32Value(UNIT_NPC_FLAGS, 0);
- setActive(false);
+ if(!isPet())
+ setActive(false);
if(!isPet() && GetCreatureInfo()->SkinLootId)
if ( LootTemplates_Skinning.HaveLootFor(GetCreatureInfo()->SkinLootId) )
@@ -1675,8 +1676,8 @@ void Creature::setDeathState(DeathState s)
}
if(s == JUST_ALIVED)
{
- if(isPet())
- setActive(true);
+ //if(isPet())
+ // setActive(true);
SetHealth(GetMaxHealth());
SetLootRecipient(NULL);
Unit::setDeathState(ALIVE);
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 33b35c0db38..12003134b1c 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -51,7 +51,7 @@ GridState* si_GridStates[MAX_GRID_STATE];
Map::~Map()
{
- UnloadAll(true);
+ UnloadAll();
}
bool Map::ExistMap(uint32 mapid,int x,int y)
@@ -1019,30 +1019,43 @@ bool Map::CreatureRespawnRelocation(Creature *c)
return false;
}
-bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce)
+bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool unloadAll)
{
NGridType *grid = getNGrid(x, y);
assert( grid != NULL);
{
- if(!pForce && PlayersNearGrid(x, y) )
- return false;
+ if(!unloadAll)
+ {
+ if(ActiveObjectsNearGrid(x, y))
+ return false;
+ }
+ else
+ assert(!PlayersNearGrid(x, y));
DEBUG_LOG("Unloading grid[%u,%u] for map %u", x,y, i_id);
ObjectGridUnloader unloader(*grid);
- // Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids
- // Must know real mob position before move
- DoDelayedMovesAndRemoves();
+ if(!unloadAll)
+ {
+ // Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids
+ // Must know real mob position before move
+ DoDelayedMovesAndRemoves();
- // move creatures to respawn grids if this is diff.grid or to remove list
- unloader.MoveToRespawnN();
+ // move creatures to respawn grids if this is diff.grid or to remove list
+ unloader.MoveToRespawnN();
- // Finish creature moves, remove and delete all creatures with delayed remove before unload
- DoDelayedMovesAndRemoves();
+ // Finish creature moves, remove and delete all creatures with delayed remove before unload
+ DoDelayedMovesAndRemoves();
+ }
+ else
+ RemoveAllObjectsInRemoveList();
+ assert(grid.NoWorldObjectInGrid());
unloader.UnloadN();
- delete getNGrid(x, y);
+ assert(grid.NoWorldObjectInGrid());
+ assert(grid.NoGridObjectInGrid());
+ delete grid;
setNGrid(NULL, x, y);
}
int gx=63-x;
@@ -1065,7 +1078,7 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce)
return true;
}
-void Map::UnloadAll(bool pForce)
+void Map::UnloadAll()
{
// clear all delayed moves, useless anyway do this moves before map unload.
i_creaturesToMove.clear();
@@ -1074,7 +1087,7 @@ void Map::UnloadAll(bool pForce)
{
NGridType &grid(*i->getSource());
++i;
- UnloadGrid(grid.getX(), grid.getY(), pForce); // deletes the grid and removes it from the GridRefManager
+ UnloadGrid(grid.getX(), grid.getY(), true); // deletes the grid and removes it from the GridRefManager
}
}
@@ -1935,7 +1948,7 @@ time_t InstanceMap::GetResetTime()
return save ? save->GetDifficulty() : DIFFICULTY_NORMAL;
}
-void InstanceMap::UnloadAll(bool pForce)
+void InstanceMap::UnloadAll()
{
if(HavePlayers())
{
@@ -1950,7 +1963,7 @@ void InstanceMap::UnloadAll(bool pForce)
if(m_resetAfterUnload == true)
objmgr.DeleteRespawnTimeForInstance(GetInstanceId());
- Map::UnloadAll(pForce);
+ Map::UnloadAll();
}
void InstanceMap::SendResetWarnings(uint32 timeLeft) const
@@ -2023,7 +2036,7 @@ void BattleGroundMap::SetUnload()
m_unloadTimer = MIN_UNLOAD_DELAY;
}
-void BattleGroundMap::UnloadAll(bool pForce)
+void BattleGroundMap::UnloadAll()
{
while(HavePlayers())
{
@@ -2035,7 +2048,7 @@ void BattleGroundMap::UnloadAll(bool pForce)
plr->GetMapRef().unlink();
}
- Map::UnloadAll(pForce);
+ Map::UnloadAll();
}
/*--------------------------TRINITY-------------------------*/
diff --git a/src/game/Map.h b/src/game/Map.h
index 10d8c914cc2..820971dae49 100644
--- a/src/game/Map.h
+++ b/src/game/Map.h
@@ -172,7 +172,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager<NGridType>, public Trinity::O
void SetUnloadFlag(const GridPair &p, bool unload) { getNGrid(p.x_coord, p.y_coord)->setUnloadFlag(unload); }
void LoadGrid(float x, float y);
bool UnloadGrid(const uint32 &x, const uint32 &y, bool pForce);
- virtual void UnloadAll(bool pForce);
+ virtual void UnloadAll();
void ResetGridExpiry(NGridType &grid, float factor = 1) const
{
@@ -367,7 +367,7 @@ class TRINITY_DLL_SPEC InstanceMap : public Map
InstanceData* GetInstanceData() { return i_data; }
void PermBindAllPlayers(Player *player);
time_t GetResetTime();
- void UnloadAll(bool pForce);
+ void UnloadAll();
bool CanEnter(Player* player);
void SendResetWarnings(uint32 timeLeft) const;
void SetResetSchedule(bool on);
@@ -388,7 +388,7 @@ class TRINITY_DLL_SPEC BattleGroundMap : public Map
void Remove(Player *, bool);
bool CanEnter(Player* player);
void SetUnload();
- void UnloadAll(bool pForce);
+ void UnloadAll();
};
/*inline
diff --git a/src/game/MapInstanced.cpp b/src/game/MapInstanced.cpp
index fe99c5c5e71..fcdc2f76c11 100644
--- a/src/game/MapInstanced.cpp
+++ b/src/game/MapInstanced.cpp
@@ -89,11 +89,11 @@ bool MapInstanced::RemoveBones(uint64 guid, float x, float y)
return remove_result || Map::RemoveBones(guid,x,y);
}
-void MapInstanced::UnloadAll(bool pForce)
+void MapInstanced::UnloadAll()
{
// Unload instanced maps
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
- i->second->UnloadAll(pForce);
+ i->second->UnloadAll();
// Delete the maps only after everything is unloaded to prevent crashes
for (InstancedMaps::iterator i = m_InstancedMaps.begin(); i != m_InstancedMaps.end(); ++i)
@@ -102,7 +102,7 @@ void MapInstanced::UnloadAll(bool pForce)
m_InstancedMaps.clear();
// Unload own grids (just dummy(placeholder) grids, neccesary to unload GridMaps!)
- Map::UnloadAll(pForce);
+ Map::UnloadAll();
}
/*
@@ -259,14 +259,14 @@ void MapInstanced::DestroyInstance(uint32 InstanceId)
// increments the iterator after erase
void MapInstanced::DestroyInstance(InstancedMaps::iterator &itr)
{
- itr->second->UnloadAll(true);
+ itr->second->UnloadAll();
// should only unload VMaps if this is the last instance and grid unloading is enabled
if(m_InstancedMaps.size() <= 1 && sWorld.getConfig(CONFIG_GRID_UNLOAD))
{
VMAP::VMapFactory::createOrGetVMapManager()->unloadMap(itr->second->GetId());
// in that case, unload grids of the base map, too
// so in the next map creation, (EnsureGridCreated actually) VMaps will be reloaded
- Map::UnloadAll(true);
+ Map::UnloadAll();
}
// erase map
delete itr->second;
diff --git a/src/game/MapInstanced.h b/src/game/MapInstanced.h
index 740a9f45fbe..830f7967d10 100644
--- a/src/game/MapInstanced.h
+++ b/src/game/MapInstanced.h
@@ -38,7 +38,7 @@ class TRINITY_DLL_DECL MapInstanced : public Map
void MoveAllCreaturesInMoveList();
void RemoveAllObjectsInRemoveList();
bool RemoveBones(uint64 guid, float x, float y);
- void UnloadAll(bool pForce);
+ void UnloadAll();
bool CanEnter(Player* player);
Map* GetInstance(const WorldObject* obj);
diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp
index 7f4d3e44f4e..4b736f83b2e 100644
--- a/src/game/MapManager.cpp
+++ b/src/game/MapManager.cpp
@@ -299,7 +299,7 @@ bool MapManager::IsValidMAP(uint32 mapid)
void MapManager::UnloadAll()
{
for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
- iter->second->UnloadAll(true);
+ iter->second->UnloadAll();
while(!i_maps.empty())
{
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 0c8d12d132a..2d19e51e76e 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -1538,7 +1538,7 @@ Map const* WorldObject::GetBaseMap() const
void WorldObject::AddObjectToRemoveList()
{
- Map* map = GetMap();
+ Map* map = MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
if(!map)
{
sLog.outError("Object (TypeId: %u Entry: %u GUID: %u) at attempt add to move list not have valid map (Id: %u).",GetTypeId(),GetEntry(),GetGUIDLow(),GetMapId());
diff --git a/src/game/Unit.h b/src/game/Unit.h
index 7d63b827e2b..c6648f00a30 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -1101,7 +1101,6 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
return false;
}
bool isPossessing(Unit* u) const { return u->isPossessed() && GetCharmGUID() == u->GetGUID(); }
- bool isPossessingCreature() const { return isPossessing() && IS_CREATURE_GUID(GetCharmGUID()); }
CharmInfo* GetCharmInfo() { return m_charmInfo; }
CharmInfo* InitCharmInfo(Unit* charm);