aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-02-24 20:05:29 -0600
committermegamage <none@none>2009-02-24 20:05:29 -0600
commitfe5fa582752175e3e44f28416ed5e534fb11c2fb (patch)
tree9b4d1023ed739a09fc2a7561ba954a4e60dfd373 /src
parenta8573dbe74d5bb0c1f0721fda4de3d619d52ebfd (diff)
*Try to fix some crash bug related to grid.
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Creature.cpp2
-rw-r--r--src/game/GridDefines.h8
-rw-r--r--src/game/Map.cpp4
-rw-r--r--src/game/Object.cpp65
-rw-r--r--src/game/Object.h6
5 files changed, 44 insertions, 41 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 0e649c66c01..ece6ea3e527 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -1675,6 +1675,8 @@ void Creature::setDeathState(DeathState s)
}
if(s == JUST_ALIVED)
{
+ if(isPet())
+ setActive(true);
SetHealth(GetMaxHealth());
SetLootRecipient(NULL);
Unit::setDeathState(ALIVE);
diff --git a/src/game/GridDefines.h b/src/game/GridDefines.h
index 9b39702d397..cb67897329f 100644
--- a/src/game/GridDefines.h
+++ b/src/game/GridDefines.h
@@ -96,24 +96,32 @@ struct TRINITY_DLL_DECL CoordPair
{
if( x_coord >= val )
x_coord -= val;
+ else
+ x_coord = 0;
}
void operator>>(const uint32 val)
{
if( x_coord+val < LIMIT )
x_coord += val;
+ else
+ x_coord = LIMIT - 1;
}
void operator-=(const uint32 val)
{
if( y_coord >= val )
y_coord -= val;
+ else
+ y_coord = 0;
}
void operator+=(const uint32 val)
{
if( y_coord+val < LIMIT )
y_coord += val;
+ else
+ y_coord = LIMIT - 1;
}
uint32 x_coord;
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index cb072d93e8d..33b35c0db38 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -474,6 +474,8 @@ Map::Add(T *obj)
AddToGrid(obj,grid,cell);
obj->AddToWorld();
+ if(obj->isActive())
+ AddActiveObject(obj);
DEBUG_LOG("Object %u enters grid[%u,%u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY());
@@ -799,6 +801,8 @@ Map::Remove(T *obj, bool remove)
assert( grid != NULL );
obj->RemoveFromWorld();
+ if(obj->isActive())
+ RemoveActiveObject(obj);
RemoveFromGrid(obj,grid,cell);
UpdateObjectVisibility(obj,cell,p);
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 6c65667c9aa..a6a4866917e 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -1070,12 +1070,6 @@ WorldObject::WorldObject()
m_isActive = false;
}
-WorldObject::~WorldObject()
-{
- if(m_isActive && !isType(TYPEMASK_PLAYER) && IsInWorld())
- GetMap()->RemoveActiveObject(this);
-}
-
void WorldObject::setActive(bool isActive)
{
// if already in the same activity state as we try to set, do nothing
@@ -1092,20 +1086,6 @@ void WorldObject::setActive(bool isActive)
}
}
-void WorldObject::AddToWorld()
-{
- Object::AddToWorld();
- if(m_isActive && !isType(TYPEMASK_PLAYER))
- GetMap()->AddActiveObject(this);
-}
-
-void WorldObject::RemoveFromWorld()
-{
- if(m_isActive && IsInWorld() && !isType(TYPEMASK_PLAYER))
- GetMap()->RemoveActiveObject(this);
- Object::RemoveFromWorld();
-}
-
void WorldObject::_Create( uint32 guidlow, HighGuid guidhigh, uint32 mapid )
{
Object::_Create(guidlow, 0, guidhigh);
@@ -1613,42 +1593,55 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa
Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, uint32 duration)
{
- Pet* pCreature = new Pet(petType);
+ Pet* pet = new Pet(petType);
+
+ if(petType == SUMMON_PET && pet->LoadPetFromDB(this, entry))
+ {
+ if(duration > 0)
+ pet->SetDuration(duration);
+ return NULL;
+ }
Map *map = GetMap();
uint32 pet_number = objmgr.GeneratePetNumber();
- if(!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, entry, pet_number))
+ if(!pet->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, entry, pet_number))
{
sLog.outError("no such creature entry %u", entry);
- delete pCreature;
+ delete pet;
return NULL;
}
- pCreature->Relocate(x, y, z, ang);
+ pet->Relocate(x, y, z, ang);
- if(!pCreature->IsPositionValid())
+ if(!pet->IsPositionValid())
{
- sLog.outError("ERROR: Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY());
- delete pCreature;
+ sLog.outError("ERROR: Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",pet->GetGUIDLow(),pet->GetEntry(),pet->GetPositionX(),pet->GetPositionY());
+ delete pet;
return NULL;
}
if(duration > 0)
- pCreature->SetDuration(duration);
+ pet->SetDuration(duration);
- pCreature->SetOwnerGUID(GetGUID());
- pCreature->SetCreatorGUID(GetGUID());
- pCreature->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction());
+ pet->SetOwnerGUID(GetGUID());
+ pet->SetCreatorGUID(GetGUID());
+ pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction());
- pCreature->GetCharmInfo()->SetPetNumber(pet_number, false);
+ pet->GetCharmInfo()->SetPetNumber(pet_number, false);
- pCreature->AIM_Initialize();
+ pet->AIM_Initialize();
- map->Add((Creature*)pCreature);
+ map->Add((Creature*)pet);
- AddGuardian(pCreature);
+ switch(petType)
+ {
+ case GUARDIAN_PET:
+ case POSSESSED_PET:
+ AddGuardian(pet);
+ break;
+ }
- return pCreature;
+ return pet;
}
GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime)
diff --git a/src/game/Object.h b/src/game/Object.h
index a485f117938..0dfb63e5997 100644
--- a/src/game/Object.h
+++ b/src/game/Object.h
@@ -350,11 +350,7 @@ class TRINITY_DLL_SPEC Object
class TRINITY_DLL_SPEC WorldObject : public Object
{
public:
- virtual ~WorldObject ( );
-
- virtual void AddToWorld();
-
- virtual void RemoveFromWorld();
+ virtual ~WorldObject ( ) {}
virtual void Update ( uint32 /*time_diff*/ ) { }