Various Cleanups (game F-K)

This commit is contained in:
Schmoozerd 2012-07-19 21:46:24 +02:00
parent c5c09cee3c
commit 2bd41afb3e
44 changed files with 1903 additions and 1881 deletions

View file

@ -74,7 +74,7 @@ GameObject::~GameObject()
void GameObject::AddToWorld()
{
///- Register the gameobject for guid lookup
if(!IsInWorld())
if (!IsInWorld())
GetMap()->GetObjectsStore().insert<GameObject>(GetObjectGuid(), (GameObject*)this);
Object::AddToWorld();
@ -83,7 +83,7 @@ void GameObject::AddToWorld()
void GameObject::RemoveFromWorld()
{
///- Remove the gameobject from the accessor
if(IsInWorld())
if (IsInWorld())
{
// Remove GO from owner
if (ObjectGuid owner_guid = GetOwnerGuid())
@ -93,7 +93,7 @@ void GameObject::RemoveFromWorld()
else
{
sLog.outError("Delete %s with SpellId %u LinkedGO %u that lost references to owner %s GO list. Crash possible later.",
GetGuidStr().c_str(), m_spellId, GetGOInfo()->GetLinkedGameObjectEntry(), owner_guid.GetString().c_str());
GetGuidStr().c_str(), m_spellId, GetGOInfo()->GetLinkedGameObjectEntry(), owner_guid.GetString().c_str());
}
}
@ -103,14 +103,14 @@ void GameObject::RemoveFromWorld()
Object::RemoveFromWorld();
}
bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, QuaternionData rotation, uint8 animprogress, GOState go_state)
bool GameObject::Create(uint32 guidlow, uint32 name_id, Map* map, uint32 phaseMask, float x, float y, float z, float ang, QuaternionData rotation, uint8 animprogress, GOState go_state)
{
MANGOS_ASSERT(map);
Relocate(x,y,z,ang);
SetMap(map);
SetPhaseMask(phaseMask,false);
if(!IsPositionValid())
if (!IsPositionValid())
{
sLog.outError("Gameobject (GUID: %u Entry: %u ) not created. Suggested coordinates are invalid (X: %f Y: %f)",guidlow,name_id,x,y);
return false;
@ -137,7 +137,7 @@ bool GameObject::Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMa
SetWorldRotation(rotation.x,rotation.y,rotation.z,rotation.w);
// For most of gameobjects is (0, 0, 0, 1) quaternion, only some transports has not standart rotation
if (const GameObjectDataAddon * addon = sGameObjectDataAddonStorage.LookupEntry<GameObjectDataAddon>(guidlow))
if (const GameObjectDataAddon* addon = sGameObjectDataAddonStorage.LookupEntry<GameObjectDataAddon>(guidlow))
SetTransportPathRotation(addon->path_rotation);
else
SetTransportPathRotation(QuaternionData(0,0,0,1));
@ -182,7 +182,7 @@ void GameObject::Update(uint32 update_diff, uint32 p_time)
{
case GO_NOT_READY:
{
switch(GetGoType())
switch (GetGoType())
{
case GAMEOBJECT_TYPE_TRAP:
{
@ -322,7 +322,7 @@ void GameObject::Update(uint32 update_diff, uint32 p_time)
if (ok)
{
Unit *caster = owner ? owner : ok;
Unit* caster = owner ? owner : ok;
caster->CastSpell(ok, goInfo->trap.spellId, true, NULL, NULL, GetObjectGuid());
// use template cooldown if provided
@ -336,7 +336,7 @@ void GameObject::Update(uint32 update_diff, uint32 p_time)
{
//BattleGround gameobjects case
if (((Player*)ok)->InBattleGround())
if (BattleGround *bg = ((Player*)ok)->GetBattleGround())
if (BattleGround* bg = ((Player*)ok)->GetBattleGround())
bg->HandleTriggerBuff(GetObjectGuid());
}
}
@ -355,7 +355,7 @@ void GameObject::Update(uint32 update_diff, uint32 p_time)
}
case GO_ACTIVATED:
{
switch(GetGoType())
switch (GetGoType())
{
case GAMEOBJECT_TYPE_DOOR:
case GAMEOBJECT_TYPE_BUTTON:
@ -483,10 +483,10 @@ void GameObject::Update(uint32 update_diff, uint32 p_time)
void GameObject::Refresh()
{
// not refresh despawned not casted GO (despawned casted GO destroyed in all cases anyway)
if(m_respawnTime > 0 && m_spawnedByDefault)
if (m_respawnTime > 0 && m_spawnedByDefault)
return;
if(isSpawned())
if (isSpawned())
GetMap()->Add(this);
}
@ -514,7 +514,7 @@ void GameObject::Delete()
AddObjectToRemoveList();
}
void GameObject::getFishLoot(Loot *fishloot, Player* loot_owner)
void GameObject::getFishLoot(Loot* fishloot, Player* loot_owner)
{
fishloot->clear();
@ -531,8 +531,8 @@ void GameObject::SaveToDB()
{
// this should only be used when the gameobject has already been loaded
// preferably after adding to map, because mapid may not be valid otherwise
GameObjectData const *data = sObjectMgr.GetGOData(GetGUIDLow());
if(!data)
GameObjectData const* data = sObjectMgr.GetGOData(GetGUIDLow());
if (!data)
{
sLog.outError("GameObject::SaveToDB failed, cannot get gameobject data!");
return;
@ -543,7 +543,7 @@ void GameObject::SaveToDB()
void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
{
const GameObjectInfo *goI = GetGOInfo();
const GameObjectInfo* goI = GetGOInfo();
if (!goI)
return;
@ -571,22 +571,22 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
// updated in DB
std::ostringstream ss;
ss << "INSERT INTO gameobject VALUES ( "
<< GetGUIDLow() << ", "
<< GetEntry() << ", "
<< mapid << ", "
<< uint32(spawnMask) << "," // cast to prevent save as symbol
<< uint16(GetPhaseMask()) << "," // prevent out of range error
<< GetPositionX() << ", "
<< GetPositionY() << ", "
<< GetPositionZ() << ", "
<< GetOrientation() << ", "
<< m_worldRotation.x << ", "
<< m_worldRotation.y << ", "
<< m_worldRotation.z << ", "
<< m_worldRotation.w << ", "
<< m_respawnDelayTime << ", "
<< uint32(GetGoAnimProgress()) << ", "
<< uint32(GetGoState()) << ")";
<< GetGUIDLow() << ", "
<< GetEntry() << ", "
<< mapid << ", "
<< uint32(spawnMask) << "," // cast to prevent save as symbol
<< uint16(GetPhaseMask()) << "," // prevent out of range error
<< GetPositionX() << ", "
<< GetPositionY() << ", "
<< GetPositionZ() << ", "
<< GetOrientation() << ", "
<< m_worldRotation.x << ", "
<< m_worldRotation.y << ", "
<< m_worldRotation.z << ", "
<< m_worldRotation.w << ", "
<< m_respawnDelayTime << ", "
<< uint32(GetGoAnimProgress()) << ", "
<< uint32(GetGoState()) << ")";
WorldDatabase.BeginTransaction();
WorldDatabase.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", GetGUIDLow());
@ -594,11 +594,11 @@ void GameObject::SaveToDB(uint32 mapid, uint8 spawnMask, uint32 phaseMask)
WorldDatabase.CommitTransaction();
}
bool GameObject::LoadFromDB(uint32 guid, Map *map)
bool GameObject::LoadFromDB(uint32 guid, Map* map)
{
GameObjectData const* data = sObjectMgr.GetGOData(guid);
if( !data )
if (!data)
{
sLog.outErrorDb("Gameobject (GUID: %u) not found in table `gameobject`, can't load. ",guid);
return false;
@ -627,7 +627,7 @@ bool GameObject::LoadFromDB(uint32 guid, Map *map)
}
else
{
if(data->spawntimesecs >= 0)
if (data->spawntimesecs >= 0)
{
m_spawnedByDefault = true;
m_respawnDelayTime = data->spawntimesecs;
@ -656,7 +656,7 @@ struct GameObjectRespawnDeleteWorker
{
explicit GameObjectRespawnDeleteWorker(uint32 guid) : i_guid(guid) {}
void operator() (MapPersistentState* state)
void operator()(MapPersistentState* state)
{
state->SaveGORespawnTime(i_guid, 0);
}
@ -682,7 +682,7 @@ void GameObject::DeleteFromDB()
WorldDatabase.PExecuteLog("DELETE FROM gameobject_battleground WHERE guid = '%u'", GetGUIDLow());
}
GameObjectInfo const *GameObject::GetGOInfo() const
GameObjectInfo const* GameObject::GetGOInfo() const
{
return m_goInfo;
}
@ -693,7 +693,7 @@ GameObjectInfo const *GameObject::GetGOInfo() const
bool GameObject::HasQuest(uint32 quest_id) const
{
QuestRelationsMapBounds bounds = sObjectMgr.GetGOQuestRelationsMapBounds(GetEntry());
for(QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
for (QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
if (itr->second == quest_id)
return true;
@ -704,7 +704,7 @@ bool GameObject::HasQuest(uint32 quest_id) const
bool GameObject::HasInvolvedQuest(uint32 quest_id) const
{
QuestRelationsMapBounds bounds = sObjectMgr.GetGOQuestInvolvedRelationsMapBounds(GetEntry());
for(QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
for (QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
if (itr->second == quest_id)
return true;
@ -715,8 +715,8 @@ bool GameObject::HasInvolvedQuest(uint32 quest_id) const
bool GameObject::IsTransport() const
{
// If something is marked as a transport, don't transmit an out of range packet for it.
GameObjectInfo const * gInfo = GetGOInfo();
if(!gInfo) return false;
GameObjectInfo const* gInfo = GetGOInfo();
if (!gInfo) return false;
return gInfo->type == GAMEOBJECT_TYPE_TRANSPORT || gInfo->type == GAMEOBJECT_TYPE_MO_TRANSPORT;
}
@ -727,29 +727,29 @@ Unit* GameObject::GetOwner() const
void GameObject::SaveRespawnTime()
{
if(m_respawnTime > time(NULL) && m_spawnedByDefault)
if (m_respawnTime > time(NULL) && m_spawnedByDefault)
GetMap()->GetPersistentState()->SaveGORespawnTime(GetGUIDLow(), m_respawnTime);
}
bool GameObject::isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const
{
// Not in world
if(!IsInWorld() || !u->IsInWorld())
if (!IsInWorld() || !u->IsInWorld())
return false;
// invisible at client always
if(!GetGOInfo()->displayId)
if (!GetGOInfo()->displayId)
return false;
// Transport always visible at this step implementation
if(IsTransport() && IsInMap(u))
if (IsTransport() && IsInMap(u))
return true;
// quick check visibility false cases for non-GM-mode
if(!u->isGameMaster())
if (!u->isGameMaster())
{
// despawned and then not visible for non-GM in GM-mode
if(!isSpawned())
if (!isSpawned())
return false;
// special invisibility cases
@ -763,19 +763,19 @@ bool GameObject::isVisibleForInState(Player const* u, WorldObject const* viewPoi
// check distance
return IsWithinDistInMap(viewPoint, GetMap()->GetVisibilityDistance() +
(inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false);
(inVisibleList ? World::GetVisibleObjectGreyDistance() : 0.0f), false);
}
void GameObject::Respawn()
{
if(m_spawnedByDefault && m_respawnTime > 0)
if (m_spawnedByDefault && m_respawnTime > 0)
{
m_respawnTime = time(NULL);
GetMap()->GetPersistentState()->SaveGORespawnTime(GetGUIDLow(), 0);
}
}
bool GameObject::ActivateToQuest(Player *pTarget) const
bool GameObject::ActivateToQuest(Player* pTarget) const
{
// if GO is ReqCreatureOrGoN for quest
if (pTarget->HasQuestForGO(GetEntry()))
@ -784,7 +784,7 @@ bool GameObject::ActivateToQuest(Player *pTarget) const
if (!sObjectMgr.IsGameObjectForQuests(GetEntry()))
return false;
switch(GetGoType())
switch (GetGoType())
{
case GAMEOBJECT_TYPE_QUESTGIVER:
{
@ -795,9 +795,9 @@ bool GameObject::ActivateToQuest(Player *pTarget) const
QuestRelationsMapBounds bounds = sObjectMgr.GetGOQuestRelationsMapBounds(GetEntry());
for(QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
for (QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
const Quest *qInfo = sObjectMgr.GetQuestTemplate(itr->second);
const Quest* qInfo = sObjectMgr.GetQuestTemplate(itr->second);
if (pTarget->CanTakeQuest(qInfo, false))
return true;
@ -805,10 +805,10 @@ bool GameObject::ActivateToQuest(Player *pTarget) const
bounds = sObjectMgr.GetGOQuestInvolvedRelationsMapBounds(GetEntry());
for(QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
for (QuestRelationsMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
{
if ((pTarget->GetQuestStatus(itr->second) == QUEST_STATUS_INCOMPLETE || pTarget->GetQuestStatus(itr->second) == QUEST_STATUS_COMPLETE)
&& !pTarget->GetQuestRewardStatus(itr->second))
&& !pTarget->GetQuestRewardStatus(itr->second))
return true;
}
@ -824,7 +824,7 @@ bool GameObject::ActivateToQuest(Player *pTarget) const
{
//look for battlegroundAV for some objects which are only activated after mine gots captured by own team
if (GetEntry() == BG_AV_OBJECTID_MINE_N || GetEntry() == BG_AV_OBJECTID_MINE_S)
if (BattleGround *bg = pTarget->GetBattleGround())
if (BattleGround* bg = pTarget->GetBattleGround())
if (bg->GetTypeID() == BATTLEGROUND_AV && !(((BattleGroundAV*)bg)->PlayerCanDoMineQuest(GetEntry(),pTarget->GetTeam())))
return false;
return true;
@ -864,7 +864,7 @@ void GameObject::SummonLinkedTrapIfAny()
GameObject* linkedGO = new GameObject;
if (!linkedGO->Create(GetMap()->GenerateLocalLowGuid(HIGHGUID_GAMEOBJECT), linkedEntry, GetMap(),
GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()))
GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()))
{
delete linkedGO;
return;
@ -942,10 +942,10 @@ void GameObject::ResetDoorOrButton()
void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = false */)
{
if(m_lootState != GO_READY)
if (m_lootState != GO_READY)
return;
if(!time_to_restore)
if (!time_to_restore)
time_to_restore = GetGOInfo()->GetAutoCloseTime();
SwitchDoorOrButton(true,alternative);
@ -956,12 +956,12 @@ void GameObject::UseDoorOrButton(uint32 time_to_restore, bool alternative /* = f
void GameObject::SwitchDoorOrButton(bool activate, bool alternative /* = false */)
{
if(activate)
if (activate)
SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
else
RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
if(GetGoState() == GO_STATE_READY) //if closed -> open
if (GetGoState() == GO_STATE_READY) //if closed -> open
SetGoState(alternative ? GO_STATE_ACTIVE_ALTERNATIVE : GO_STATE_ACTIVE);
else //if open -> close
SetGoState(GO_STATE_READY);
@ -1103,7 +1103,7 @@ void GameObject::Use(Unit* user)
// every slot will be on that straight line
float orthogonalOrientation = GetOrientation() + M_PI_F * 0.5f;
// find nearest slot
for(uint32 i=0; i<info->chair.slots; ++i)
for (uint32 i=0; i<info->chair.slots; ++i)
{
// the distance between this slot and the center of the go - imagine a 1D space
float relativeDistance = (info->size*i)-(info->size*(info->chair.slots-1)/2.0f);
@ -1207,7 +1207,7 @@ void GameObject::Use(Unit* user)
spellId = info->goober.spellId;
// database may contain a dummy spell, so it need replacement by actually existing
switch(spellId)
switch (spellId)
{
case 34448: spellId = 26566; break;
case 34452: spellId = 26572; break;
@ -1523,7 +1523,7 @@ void GameObject::Use(Unit* user)
if (player->CanUseBattleGroundObject())
{
// in battleground check
BattleGround *bg = player->GetBattleGround();
BattleGround* bg = player->GetBattleGround();
if (!bg)
return;
// BG flag dropped
@ -1535,7 +1535,7 @@ void GameObject::Use(Unit* user)
GameObjectInfo const* info = GetGOInfo();
if (info)
{
switch(info->id)
switch (info->id)
{
case 179785: // Silverwing Flag
case 179786: // Warsong Flag
@ -1583,14 +1583,14 @@ void GameObject::Use(Unit* user)
if (!spellId)
return;
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo)
{
sLog.outError("WORLD: unknown spell id %u at use action for gameobject (Entry: %u GoType: %u )", spellId, GetEntry(), GetGoType());
return;
}
Spell *spell = new Spell(spellCaster, spellInfo, triggered, GetObjectGuid());
Spell* spell = new Spell(spellCaster, spellInfo, triggered, GetObjectGuid());
// spell target is user of GO
SpellCastTargets targets;
@ -1604,7 +1604,7 @@ const char* GameObject::GetNameForLocaleIdx(int32 loc_idx) const
{
if (loc_idx >= 0)
{
GameObjectLocale const *cl = sObjectMgr.GetGameObjectLocale(GetEntry());
GameObjectLocale const* cl = sObjectMgr.GetGameObjectLocale(GetEntry());
if (cl)
{
if (cl->Name.size() > (size_t)loc_idx && !cl->Name[loc_idx].empty())
@ -1622,7 +1622,8 @@ struct QuaternionCompressed
QuaternionCompressed(int64 val) : m_raw(val) {}
QuaternionCompressed(const Quat& quat) { Set(quat); }
enum{
enum
{
PACK_COEFF_YZ = 1 << 20,
PACK_COEFF_X = 1 << 21,
};
@ -1676,7 +1677,7 @@ void GameObject::SetTransportPathRotation(QuaternionData rotation)
void GameObject::SetWorldRotationAngles(float z_rot, float y_rot, float x_rot)
{
Quat quat( G3D::Matrix3::fromEulerAnglesZYX(z_rot, y_rot, x_rot) );
Quat quat(G3D::Matrix3::fromEulerAnglesZYX(z_rot, y_rot, x_rot));
SetWorldRotation(quat.x, quat.y, quat.z, quat.w);
}
@ -1698,8 +1699,8 @@ bool GameObject::IsHostileTo(Unit const* unit) const
return true;
// faction base cases
FactionTemplateEntry const*tester_faction = sFactionTemplateStore.LookupEntry(GetGOInfo()->faction);
FactionTemplateEntry const*target_faction = unit->getFactionTemplateEntry();
FactionTemplateEntry const* tester_faction = sFactionTemplateStore.LookupEntry(GetGOInfo()->faction);
FactionTemplateEntry const* target_faction = unit->getFactionTemplateEntry();
if (!tester_faction || !target_faction)
return false;
@ -1741,8 +1742,8 @@ bool GameObject::IsFriendlyTo(Unit const* unit) const
return false;
// faction base cases
FactionTemplateEntry const*tester_faction = sFactionTemplateStore.LookupEntry(GetGOInfo()->faction);
FactionTemplateEntry const*target_faction = unit->getFactionTemplateEntry();
FactionTemplateEntry const* tester_faction = sFactionTemplateStore.LookupEntry(GetGOInfo()->faction);
FactionTemplateEntry const* target_faction = unit->getFactionTemplateEntry();
if (!tester_faction || !target_faction)
return false;
@ -1877,7 +1878,7 @@ struct AddGameObjectToRemoveListInMapsWorker
{
AddGameObjectToRemoveListInMapsWorker(ObjectGuid guid) : i_guid(guid) {}
void operator() (Map* map)
void operator()(Map* map)
{
if (GameObject* pGameobject = map->GetGameObject(i_guid))
pGameobject->AddObjectToRemoveList();
@ -1897,7 +1898,7 @@ struct SpawnGameObjectInMapsWorker
SpawnGameObjectInMapsWorker(uint32 guid, GameObjectData const* data)
: i_guid(guid), i_data(data) {}
void operator() (Map* map)
void operator()(Map* map)
{
// Spawn if necessary (loaded grids only)
if (map->IsLoaded(i_data->posX, i_data->posY))