*Try to fix some crash bug related to grid.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-02-24 20:05:29 -06:00
parent a8573dbe74
commit fe5fa58275
5 changed files with 48 additions and 45 deletions
+2
View File
@@ -1675,6 +1675,8 @@ void Creature::setDeathState(DeathState s)
}
if(s == JUST_ALIVED)
{
if(isPet())
setActive(true);
SetHealth(GetMaxHealth());
SetLootRecipient(NULL);
Unit::setDeathState(ALIVE);
+8
View File
@@ -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;
+4
View File
@@ -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);
+33 -40
View File
@@ -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);
Map *map = GetMap();
uint32 pet_number = objmgr.GeneratePetNumber();
if(!pCreature->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, entry, pet_number))
if(petType == SUMMON_PET && pet->LoadPetFromDB(this, entry))
{
sLog.outError("no such creature entry %u", entry);
delete pCreature;
if(duration > 0)
pet->SetDuration(duration);
return NULL;
}
pCreature->Relocate(x, y, z, ang);
if(!pCreature->IsPositionValid())
Map *map = GetMap();
uint32 pet_number = objmgr.GeneratePetNumber();
if(!pet->Create(objmgr.GenerateLowGuid(HIGHGUID_PET), map, entry, pet_number))
{
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("no such creature entry %u", entry);
delete pet;
return NULL;
}
pet->Relocate(x, y, z, ang);
if(!pet->IsPositionValid())
{
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)
+1 -5
View File
@@ -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*/ ) { }