Make typecasting methods *really* safe and get rid of redundant typeId/Typemask checks, thanks Zor and Machiavelli for help

--HG--
branch : trunk
This commit is contained in:
Shauren
2010-08-05 17:01:25 +02:00
parent 30194bdd61
commit c94046b065
6 changed files with 98 additions and 8 deletions
+9 -4
View File
@@ -116,6 +116,7 @@ class CreatureAI;
class ZoneScript;
class Unit;
class Transport;
class Item;
typedef UNORDERED_MAP<Player*, UpdateData> UpdateDataMapType;
@@ -320,10 +321,14 @@ class Object
// FG: some hacky helpers
void ForceValuesUpdateAtIndex(uint32);
Player* ToPlayer(){ if (GetTypeId() == TYPEID_PLAYER) return reinterpret_cast<Player*>(this); else return NULL; }
const Player* ToPlayer() const { if (GetTypeId() == TYPEID_PLAYER) return (const Player*)((Player*)this); else return NULL; }
Creature* ToCreature(){ if (GetTypeId() == TYPEID_UNIT) return reinterpret_cast<Creature*>(this); else return NULL; }
const Creature* ToCreature() const {if (GetTypeId() == TYPEID_UNIT) return (const Creature*)((Creature*)this); else return NULL; }
Unit* ToUnit();
const Unit* ToUnit() const;
Player* ToPlayer();
const Player* ToPlayer() const;
Creature* ToCreature();
const Creature* ToCreature() const;
Item* ToItem();
const Item* ToItem() const;
protected: