Core/Transports: Enabled LoS on transports

This commit is contained in:
Shauren
2014-03-23 00:23:30 +01:00
parent 3a1a55bb0a
commit 550cbcad96
6 changed files with 71 additions and 9 deletions

View File

@@ -130,17 +130,13 @@ bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayIn
for (int i = 0; i < 8; ++i)
rotated_bounds.merge(iRotation * mdl_box.corner(i));
this->iBound = rotated_bounds + iPos;
iBound = rotated_bounds + iPos;
#ifdef SPAWN_CORNERS
// test:
for (int i = 0; i < 8; ++i)
{
Vector3 pos(iBound.corner(i));
if (Creature* c = const_cast<GameObject&>(go).SummonCreature(24440, pos.x, pos.y, pos.z, 0, TEMPSUMMON_MANUAL_DESPAWN))
{
c->setFaction(35);
c->SetObjectScale(0.1f);
}
go.SummonCreature(1, pos.x, pos.y, pos.z, 0, TEMPSUMMON_MANUAL_DESPAWN);
}
#endif
@@ -184,3 +180,43 @@ bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool Sto
}
return hit;
}
bool GameObjectModel::Relocate(const GameObject& go)
{
if (!iModel)
return false;
ModelList::const_iterator it = model_list.find(go.GetDisplayId());
if (it == model_list.end())
return false;
G3D::AABox mdl_box(it->second.bound);
// ignore models with no bounds
if (mdl_box == G3D::AABox::zero())
{
VMAP_ERROR_LOG("misc", "GameObject model %s has zero bounds, loading skipped", it->second.name.c_str());
return false;
}
iPos = Vector3(go.GetPositionX(), go.GetPositionY(), go.GetPositionZ());
G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(go.GetOrientation(), 0, 0);
iInvRot = iRotation.inverse();
// transform bounding box:
mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
AABox rotated_bounds;
for (int i = 0; i < 8; ++i)
rotated_bounds.merge(iRotation * mdl_box.corner(i));
iBound = rotated_bounds + iPos;
#ifdef SPAWN_CORNERS
// test:
for (int i = 0; i < 8; ++i)
{
Vector3 pos(iBound.corner(i));
go.SummonCreature(1, pos.x, pos.y, pos.z, 0, TEMPSUMMON_MANUAL_DESPAWN);
}
#endif
return true;
}

View File

@@ -66,6 +66,8 @@ public:
bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const;
static GameObjectModel* Create(const GameObject& go);
bool Relocate(GameObject const& go);
};
#endif // _GAMEOBJECT_MODEL_H
#endif // _GAMEOBJECT_MODEL_H

View File

@@ -148,7 +148,7 @@ void GameObject::AddToWorld()
sObjectAccessor->AddObject(this);
// The state can be changed after GameObject::Create but before GameObject::AddToWorld
bool toggledState = GetGoType() == GAMEOBJECT_TYPE_CHEST ? getLootState() == GO_READY : GetGoState() == GO_STATE_READY;
bool toggledState = GetGoType() == GAMEOBJECT_TYPE_CHEST ? getLootState() == GO_READY : (GetGoState() == GO_STATE_READY || IsTransport());
if (m_model)
GetMap()->InsertGameObjectModel(*m_model);
@@ -2020,7 +2020,7 @@ void GameObject::SetGoState(GOState state)
{
SetByteValue(GAMEOBJECT_BYTES_1, 0, state);
sScriptMgr->OnGameObjectStateChanged(this, state);
if (m_model)
if (m_model && !IsTransport())
{
if (!IsInWorld())
return;
@@ -2239,3 +2239,16 @@ float GameObject::GetInteractionDistance()
return INTERACTION_DISTANCE;
}
}
void GameObject::UpdateModelPosition()
{
if (!m_model)
return;
if (GetMap()->ContainsGameObjectModel(*m_model))
{
GetMap()->RemoveGameObjectModel(*m_model);
m_model->Relocate(*this);
GetMap()->InsertGameObjectModel(*m_model);
}
}

View File

@@ -832,6 +832,8 @@ class GameObject : public WorldObject, public GridObject<GameObject>, public Map
float GetInteractionDistance();
void UpdateModelPosition();
protected:
bool AIM_Initialize();
void UpdateModel(); // updates model in case displayId were changed

View File

@@ -95,6 +95,8 @@ bool Transport::Create(uint32 guidlow, uint32 entry, uint32 mapid, float x, floa
SetGoAnimProgress(animprogress);
SetName(goinfo->name);
UpdateRotationFields(0.0f, 1.0f);
m_model = GameObjectModel::Create(*this);
return true;
}
@@ -217,6 +219,9 @@ void Transport::Update(uint32 diff)
void Transport::AddPassenger(WorldObject* passenger)
{
if (!IsInWorld())
return;
if (_passengers.insert(passenger).second)
{
TC_LOG_DEBUG("entities.transport", "Object %s boarded transport %s.", passenger->GetName().c_str(), GetName().c_str());
@@ -328,6 +333,7 @@ void Transport::UpdatePosition(float x, float y, float z, float o)
bool newActive = GetMap()->IsGridLoaded(x, y);
Relocate(x, y, z, o);
UpdateModelPosition();
UpdatePassengerPositions(_passengers);
@@ -474,6 +480,7 @@ bool Transport::TeleportTransport(uint32 newMapid, float x, float y, float z, fl
}
Relocate(x, y, z, o);
UpdateModelPosition();
GetMap()->AddToMap<Transport>(this);
return true;
}

View File

@@ -954,6 +954,7 @@ void Map::GameObjectRelocation(GameObject* go, float x, float y, float z, float
else
{
go->Relocate(x, y, z, orientation);
go->UpdateModelPosition();
go->UpdateObjectVisibility(false);
RemoveGameObjectFromMoveList(go);
}
@@ -1132,6 +1133,7 @@ void Map::MoveAllGameObjectsInMoveList()
{
// update pos
go->Relocate(go->_newPosition);
go->UpdateModelPosition();
go->UpdateObjectVisibility(false);
}
else