aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/Collision/Models/GameObjectModel.cpp7
-rw-r--r--src/common/Collision/Models/GameObjectModel.h2
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp19
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h2
4 files changed, 17 insertions, 13 deletions
diff --git a/src/common/Collision/Models/GameObjectModel.cpp b/src/common/Collision/Models/GameObjectModel.cpp
index 7e8d0b9d438..5d8712561f6 100644
--- a/src/common/Collision/Models/GameObjectModel.cpp
+++ b/src/common/Collision/Models/GameObjectModel.cpp
@@ -140,14 +140,11 @@ bool GameObjectModel::initialize(std::unique_ptr<GameObjectModelOwnerBase> model
return true;
}
-GameObjectModel* GameObjectModel::Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath)
+std::unique_ptr<GameObjectModel> GameObjectModel::Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath)
{
- GameObjectModel* mdl = new GameObjectModel();
+ std::unique_ptr<GameObjectModel> mdl(new GameObjectModel());
if (!mdl->initialize(std::move(modelOwner), dataPath))
- {
- delete mdl;
return nullptr;
- }
return mdl;
}
diff --git a/src/common/Collision/Models/GameObjectModel.h b/src/common/Collision/Models/GameObjectModel.h
index c55ac34e482..2ea99f61e20 100644
--- a/src/common/Collision/Models/GameObjectModel.h
+++ b/src/common/Collision/Models/GameObjectModel.h
@@ -79,7 +79,7 @@ public:
bool GetLocationInfo(G3D::Vector3 const& point, VMAP::LocationInfo& info, PhaseShift const& phaseShift) const;
bool GetLiquidLevel(G3D::Vector3 const& point, VMAP::LocationInfo& info, float& liqHeight) const;
- static GameObjectModel* Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath);
+ static std::unique_ptr<GameObjectModel> Create(std::unique_ptr<GameObjectModelOwnerBase> modelOwner, std::string const& dataPath);
bool UpdatePosition();
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index b43c8c19049..e09930d9fd1 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -833,7 +833,7 @@ void SetControlZoneValue::Execute(GameObjectTypeBase& type) const
}
GameObject::GameObject() : WorldObject(false), MapObject(),
- m_model(nullptr), m_goValue(), m_stringIds(), m_AI(nullptr), m_respawnCompatibilityMode(false), _animKitId(0), _worldEffectID(0)
+ m_goValue(), m_stringIds(), m_AI(nullptr), m_respawnCompatibilityMode(false), _animKitId(0), _worldEffectID(0)
{
m_objectType |= TYPEMASK_GAMEOBJECT;
m_objectTypeId = TYPEID_GAMEOBJECT;
@@ -868,7 +868,6 @@ GameObject::GameObject() : WorldObject(false), MapObject(),
GameObject::~GameObject()
{
delete m_AI;
- delete m_model;
}
void GameObject::AIM_Destroy()
@@ -3744,7 +3743,6 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
m_goValue.Building.Health = m_goValue.Building.DestructibleHitpoint->GetMaxHealth();
SetGoAnimProgress(255);
}
- EnableCollision(true);
break;
case GO_DESTRUCTIBLE_DAMAGED:
{
@@ -3792,7 +3790,6 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
m_goValue.Building.Health = 0;
SetGoAnimProgress(0);
}
- EnableCollision(false);
break;
}
case GO_DESTRUCTIBLE_REBUILDING:
@@ -3813,7 +3810,6 @@ void GameObject::SetDestructibleState(GameObjectDestructibleState state, WorldOb
m_goValue.Building.Health = m_goValue.Building.DestructibleHitpoint->GetMaxHealth();
SetGoAnimProgress(255);
}
- EnableCollision(true);
break;
}
}
@@ -4007,15 +4003,26 @@ void GameObject::UpdateModel()
{
if (!IsInWorld())
return;
+ bool modelCollisionEnabled;
if (m_model)
+ {
+ modelCollisionEnabled = m_model->IsCollisionEnabled();
if (GetMap()->ContainsGameObjectModel(*m_model))
GetMap()->RemoveGameObjectModel(*m_model);
+ }
+ else
+ modelCollisionEnabled = GetGoType() == GAMEOBJECT_TYPE_CHEST ? getLootState() == GO_READY : (GetGoState() == GO_STATE_READY || IsTransport());
+
RemoveFlag(GO_FLAG_MAP_OBJECT);
- delete m_model;
m_model = nullptr;
+
CreateModel();
if (m_model)
+ {
GetMap()->InsertGameObjectModel(*m_model);
+ if (modelCollisionEnabled)
+ m_model->EnableCollision(modelCollisionEnabled);
+ }
}
bool GameObject::IsLootAllowedFor(Player const* player) const
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index 40c38ac3518..800ef83a09e 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -396,7 +396,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
uint32 GetFaction() const override { return m_gameObjectData->FactionTemplate; }
void SetFaction(uint32 faction) override { SetUpdateFieldValue(m_values.ModifyValue(&GameObject::m_gameObjectData).ModifyValue(&UF::GameObjectData::FactionTemplate), faction); }
- GameObjectModel* m_model;
+ std::unique_ptr<GameObjectModel> m_model;
Position GetRespawnPosition() const;
TransportBase* ToTransportBase() { return const_cast<TransportBase*>(const_cast<GameObject const*>(this)->ToTransportBase()); }