From 629908172fb5ac2f515f9474cdf6aba1b331958b Mon Sep 17 00:00:00 2001 From: Treeston Date: Thu, 6 Aug 2020 19:46:20 +0200 Subject: Core/Object: Deduplicate some checks --- src/server/game/Entities/Object/Object.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 24ae1450df5..a95289937fd 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -158,38 +158,38 @@ class TC_GAME_API Object void ForceValuesUpdateAtIndex(uint32); inline bool IsPlayer() const { return GetTypeId() == TYPEID_PLAYER; } - static Player* ToPlayer(Object* o) { if (o && o->GetTypeId() == TYPEID_PLAYER) return reinterpret_cast(o); else return nullptr; } - static Player const* ToPlayer(Object const* o) { if (o && o->GetTypeId() == TYPEID_PLAYER) return reinterpret_cast(o); else return nullptr; } + static Player* ToPlayer(Object* o) { if (o && o->IsPlayer()) return reinterpret_cast(o); else return nullptr; } + static Player const* ToPlayer(Object const* o) { if (o && o->IsPlayer()) return reinterpret_cast(o); else return nullptr; } Player* ToPlayer() { return ToPlayer(this); } Player const* ToPlayer() const { return ToPlayer(this); } inline bool IsCreature() const { return GetTypeId() == TYPEID_UNIT; } - static Creature* ToCreature(Object* o) { if (o && o->GetTypeId() == TYPEID_UNIT) return reinterpret_cast(o); else return nullptr; } - static Creature const* ToCreature(Object const* o) { if (o && o->GetTypeId() == TYPEID_UNIT) return reinterpret_cast(o); else return nullptr; } + static Creature* ToCreature(Object* o) { if (o && o->IsCreature()) return reinterpret_cast(o); else return nullptr; } + static Creature const* ToCreature(Object const* o) { if (o && o->IsCreature()) return reinterpret_cast(o); else return nullptr; } Creature* ToCreature() { return ToCreature(this); } Creature const* ToCreature() const { return ToCreature(this); } inline bool IsUnit() const { return isType(TYPEMASK_UNIT); } - static Unit* ToUnit(Object* o) { if (o && o->isType(TYPEMASK_UNIT)) return reinterpret_cast(o); else return nullptr; } - static Unit const* ToUnit(Object const* o) { if (o && o->isType(TYPEMASK_UNIT)) return reinterpret_cast(o); else return nullptr; } + static Unit* ToUnit(Object* o) { if (o && o->IsUnit()) return reinterpret_cast(o); else return nullptr; } + static Unit const* ToUnit(Object const* o) { if (o && o->IsUnit()) return reinterpret_cast(o); else return nullptr; } Unit* ToUnit() { return ToUnit(this); } Unit const* ToUnit() const { return ToUnit(this); } inline bool IsGameObject() const { return GetTypeId() == TYPEID_GAMEOBJECT; } - static GameObject* ToGameObject(Object* o) { if (o && o->GetTypeId() == TYPEID_GAMEOBJECT) return reinterpret_cast(o); else return nullptr; } - static GameObject const* ToGameObject(Object const* o) { if (o && o->GetTypeId() == TYPEID_GAMEOBJECT) return reinterpret_cast(o); else return nullptr; } + static GameObject* ToGameObject(Object* o) { if (o && o->IsGameObject()) return reinterpret_cast(o); else return nullptr; } + static GameObject const* ToGameObject(Object const* o) { if (o && o->IsGameObject()) return reinterpret_cast(o); else return nullptr; } GameObject* ToGameObject() { return ToGameObject(this); } GameObject const* ToGameObject() const { return ToGameObject(this); } inline bool IsCorpse() const { return GetTypeId() == TYPEID_CORPSE; } - static Corpse* ToCorpse(Object* o) { if (o && o->GetTypeId() == TYPEID_CORPSE) return reinterpret_cast(o); else return nullptr; } - static Corpse const* ToCorpse(Object const* o) { if (o && o->GetTypeId() == TYPEID_CORPSE) return reinterpret_cast(o); else return nullptr; } + static Corpse* ToCorpse(Object* o) { if (o && o->IsCorpse()) return reinterpret_cast(o); else return nullptr; } + static Corpse const* ToCorpse(Object const* o) { if (o && o->IsCorpse()) return reinterpret_cast(o); else return nullptr; } Corpse* ToCorpse() { return ToCorpse(this); } Corpse const* ToCorpse() const { return ToCorpse(this); } inline bool IsDynObject() const { return GetTypeId() == TYPEID_DYNAMICOBJECT; } - static DynamicObject* ToDynObject(Object* o) { if (o && o->GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast(o); else return nullptr; } - static DynamicObject const* ToDynObject(Object const* o) { if (o && o->GetTypeId() == TYPEID_DYNAMICOBJECT) return reinterpret_cast(o); else return nullptr; } + static DynamicObject* ToDynObject(Object* o) { if (o && o->IsDynObject()) return reinterpret_cast(o); else return nullptr; } + static DynamicObject const* ToDynObject(Object const* o) { if (o && o->IsDynObject()) return reinterpret_cast(o); else return nullptr; } DynamicObject* ToDynObject() { return ToDynObject(this); } DynamicObject const* ToDynObject() const { return ToDynObject(this); } -- cgit v1.2.3