aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/collision/Models/GameObjectModel.cpp48
-rw-r--r--src/server/collision/Models/GameObjectModel.h4
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp17
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h2
-rw-r--r--src/server/game/Entities/Transport/Transport.cpp7
-rw-r--r--src/server/game/Maps/Map.cpp2
6 files changed, 71 insertions, 9 deletions
diff --git a/src/server/collision/Models/GameObjectModel.cpp b/src/server/collision/Models/GameObjectModel.cpp
index d254a640279..42584693a13 100644
--- a/src/server/collision/Models/GameObjectModel.cpp
+++ b/src/server/collision/Models/GameObjectModel.cpp
@@ -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;
+}
diff --git a/src/server/collision/Models/GameObjectModel.h b/src/server/collision/Models/GameObjectModel.h
index a1c0942dab4..6088b924343 100644
--- a/src/server/collision/Models/GameObjectModel.h
+++ b/src/server/collision/Models/GameObjectModel.h
@@ -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 \ No newline at end of file
+#endif // _GAMEOBJECT_MODEL_H
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 80171edd715..e58a9be3249 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -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);
+ }
+}
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index 84abc391bc6..48db64a3687 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -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
diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp
index a07cc5f73af..9e05ade2a21 100644
--- a/src/server/game/Entities/Transport/Transport.cpp
+++ b/src/server/game/Entities/Transport/Transport.cpp
@@ -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;
}
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 0fc56516c56..8dc393c5f85 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -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