Remove/Add creature from/to map when it changes map.

Note: creatures was never supposed to change map, but now the core allows them to move with transports...
This commit is contained in:
megamage
2011-10-10 17:59:52 -04:00
parent 3ba22d0d06
commit 3569121d80
3 changed files with 12 additions and 13 deletions
+5 -12
View File
@@ -2387,22 +2387,15 @@ const char* Creature::GetNameForLocaleIdx(LocaleConstant loc_idx) const
return GetName(); return GetName();
} }
//TODO: This may cause crash. Creature must be removed from the original grid and added to the new grid. //Do not if this works or not, moving creature to another map is very dangerous
void Creature::FarTeleportTo(Map* map, float X, float Y, float Z, float O) void Creature::FarTeleportTo(Map* map, float X, float Y, float Z, float O)
{ {
InterruptNonMeleeSpells(true); CleanupBeforeRemoveFromMap(false);
CombatStop(); GetMap()->RemoveFromMap(this, false);
ClearComboPointHolders();
DeleteThreatList();
GetMotionMaster()->Clear(false);
DestroyForNearbyPlayers();
RemoveFromWorld();
ResetMap(); ResetMap();
Relocate(X, Y, Z, O);
SetMap(map); SetMap(map);
AddToWorld(); GetMap()->AddToMap(this);
UpdatePosition(X, Y, Z, O, true);
} }
void Creature::SetPosition(float x, float y, float z, float o) void Creature::SetPosition(float x, float y, float z, float o)
+6 -1
View File
@@ -13710,7 +13710,7 @@ void Unit::RemoveFromWorld()
} }
} }
void Unit::CleanupsBeforeDelete(bool finalCleanup) void Unit::CleanupBeforeRemoveFromMap(bool finalCleanup)
{ {
// This needs to be before RemoveFromWorld to make GetCaster() return a valid pointer on aura removal // This needs to be before RemoveFromWorld to make GetCaster() return a valid pointer on aura removal
InterruptNonMeleeSpells(true); InterruptNonMeleeSpells(true);
@@ -13734,6 +13734,11 @@ void Unit::CleanupsBeforeDelete(bool finalCleanup)
DeleteThreatList(); DeleteThreatList();
getHostileRefManager().setOnlineOfflineState(false); getHostileRefManager().setOnlineOfflineState(false);
GetMotionMaster()->Clear(false); // remove different non-standard movement generators. GetMotionMaster()->Clear(false); // remove different non-standard movement generators.
}
void Unit::CleanupsBeforeDelete(bool finalCleanup)
{
CleanupBeforeRemoveFromMap(finalCleanup);
if (Creature* thisCreature = ToCreature()) if (Creature* thisCreature = ToCreature())
if (GetTransport()) if (GetTransport())
+1
View File
@@ -1247,6 +1247,7 @@ class Unit : public WorldObject
void AddToWorld(); void AddToWorld();
void RemoveFromWorld(); void RemoveFromWorld();
void CleanupBeforeRemoveFromMap(bool finalCleanup);
void CleanupsBeforeDelete(bool finalCleanup = true); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units) void CleanupsBeforeDelete(bool finalCleanup = true); // used in ~Creature/~Player (or before mass creature delete to remove cross-references to already deleted units)
DiminishingLevels GetDiminishing(DiminishingGroup group); DiminishingLevels GetDiminishing(DiminishingGroup group);