aboutsummaryrefslogtreecommitdiff
path: root/src/game/Object.cpp
diff options
context:
space:
mode:
authorraczman <none@none>2010-03-07 15:20:19 +0100
committerraczman <none@none>2010-03-07 15:20:19 +0100
commit91b8ee104eac7446f9b8cbea7ed9dce641740c8e (patch)
tree2866b76745089d8066dad65b63e5aff07e92f4f6 /src/game/Object.cpp
parentaeebe57dc08d8b2d90972f50f00c4a28dd3947ba (diff)
Added new type-safe cast functions.
This, when properly used, should get rid of most memory corruption issues, currently, casting types C-style with no checks leads to some abstract crashing. Functionality is same as with dynamic_cast<>, but with no RTTI check - so when casting into invalid type you will receive NULL, and most probably crash. At the same time, i took the liberty to convert most Player* casts to ToPlayer(). Still needs crapload of casts being moved to new facility. --HG-- branch : trunk
Diffstat (limited to 'src/game/Object.cpp')
-rw-r--r--src/game/Object.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/game/Object.cpp b/src/game/Object.cpp
index 40cac8a7891..21c564c6dcb 100644
--- a/src/game/Object.cpp
+++ b/src/game/Object.cpp
@@ -295,11 +295,11 @@ void Object::_BuildMovementUpdate(ByteBuffer * data, uint16 flags) const
*data << ((Unit*)this)->GetSpeed( MOVE_PITCH_RATE );
// 0x08000000
- if(GetTypeId() == TYPEID_PLAYER && ((Player*)this)->isInFlight())
+ if(GetTypeId() == TYPEID_PLAYER && this->ToPlayer()->isInFlight())
{
- WPAssert(((Player*)this)->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE);
+ //WPAssert(this->ToPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE);
- FlightPathMovementGenerator *fmg = (FlightPathMovementGenerator*)(((Player*)this)->GetMotionMaster()->top());
+ FlightPathMovementGenerator *fmg = (FlightPathMovementGenerator*)(const_cast<Player*>(this->ToPlayer())->GetMotionMaster()->top());
uint32 flags3 = MOVEFLAG_GLIDE;
@@ -327,7 +327,7 @@ void Object::_BuildMovementUpdate(ByteBuffer * data, uint16 flags) const
Path &path = fmg->GetPath();
float x, y, z;
- ((Player*)this)->GetPosition(x, y, z);
+ this->ToPlayer()->GetPosition(x, y, z);
uint32 inflighttime = uint32(path.GetPassedLength(fmg->GetCurrentNode(), x, y, z) * 32);
uint32 traveltime = uint32(path.GetTotalLength() * 32);
@@ -629,14 +629,14 @@ void Object::_BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask
if(index == UNIT_FIELD_BYTES_2)
{
// Allow targetting opposite faction in party when enabled in config
- DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (flag)", target->GetName(), ((Player*)this)->GetName());
+ DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (flag)", target->GetName(), this->ToPlayer()->GetName());
*data << ( m_uint32Values[ index ] & ((UNIT_BYTE2_FLAG_SANCTUARY /*| UNIT_BYTE2_FLAG_AURAS | UNIT_BYTE2_FLAG_UNK5*/) << 8) ); // this flag is at uint8 offset 1 !!
}
else
{
// pretend that all other HOSTILE players have own faction, to allow follow, heal, rezz (trade wont work)
uint32 faction = target->getFaction();
- DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (faction %u)", target->GetName(), ((Player*)this)->GetName(), faction);
+ DEBUG_LOG("-- VALUES_UPDATE: Sending '%s' the blue-group-fix from '%s' (faction %u)", target->GetName(), this->ToPlayer()->GetName(), faction);
*data << uint32(faction);
}
}
@@ -1487,7 +1487,7 @@ void WorldObject::SendPlaySound(uint32 Sound, bool OnlySelf)
WorldPacket data(SMSG_PLAY_SOUND, 4);
data << Sound;
if (OnlySelf && GetTypeId() == TYPEID_PLAYER)
- ((Player*)this)->GetSession()->SendPacket( &data );
+ this->ToPlayer()->GetSession()->SendPacket( &data );
else
SendMessageToSet( &data, true ); // ToSelf ignored in this case
}
@@ -1735,7 +1735,7 @@ TempSummon *Map::SummonCreature(uint32 entry, const Position &pos, SummonPropert
{
phase = summoner->GetPhaseMask();
if(summoner->GetTypeId() == TYPEID_PLAYER)
- team = ((Player*)summoner)->GetTeam();
+ team = summoner->ToPlayer()->GetTeam();
}
TempSummon *summon = NULL;