[9232] Replace list bool fields with exclusive true values by subtype field in Creature.

Use it in recently added code instead dynamic_cast use.
This commit is contained in:
VladimirMangos 2010-01-21 22:20:50 +03:00
parent 6653539a5e
commit 797dd6d931
9 changed files with 29 additions and 21 deletions

View file

@ -111,13 +111,12 @@ bool ForcedDespawnDelayEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
return true; return true;
} }
Creature::Creature() : Creature::Creature(CreatureSubtype subtype) :
Unit(), i_AI(NULL), Unit(), i_AI(NULL),
lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0), lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0),
m_lootMoney(0), m_lootRecipient(0), m_lootMoney(0), m_lootRecipient(0),
m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f), m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f),
m_isPet(false), m_isVehicle(false), m_isTotem(false), m_subtype(subtype), m_defaultMovementType(IDLE_MOTION_TYPE), m_DBTableGuid(0), m_equipmentId(0),
m_defaultMovementType(IDLE_MOTION_TYPE), m_DBTableGuid(0), m_equipmentId(0),
m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false), m_AlreadyCallAssistance(false), m_AlreadySearchedAssistance(false),
m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false), m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),
m_creatureInfo(NULL), m_isActiveObject(false), m_monsterMoveFlags(MONSTER_MOVE_WALK) m_creatureInfo(NULL), m_isActiveObject(false), m_monsterMoveFlags(MONSTER_MOVE_WALK)

View file

@ -361,13 +361,22 @@ typedef std::map<uint32,time_t> CreatureSpellCooldowns;
#define MAX_VENDOR_ITEMS 150 // Limitation in 3.x.x item count in SMSG_LIST_INVENTORY #define MAX_VENDOR_ITEMS 150 // Limitation in 3.x.x item count in SMSG_LIST_INVENTORY
enum CreatureSubtype
{
CREATURE_SUBTYPE_GENERIC, // new Creature
CREATURE_SUBTYPE_PET, // new Pet
CREATURE_SUBTYPE_TOTEM, // new Totem
CREATURE_SUBTYPE_VEHICLE, // new Vehicle
CREATURE_SUBTYPE_TEMPORARY_SUMMON, // new TemporarySummon
};
class MANGOS_DLL_SPEC Creature : public Unit class MANGOS_DLL_SPEC Creature : public Unit
{ {
CreatureAI *i_AI; CreatureAI *i_AI;
public: public:
explicit Creature(); explicit Creature(CreatureSubtype subtype = CREATURE_SUBTYPE_GENERIC);
virtual ~Creature(); virtual ~Creature();
void AddToWorld(); void AddToWorld();
@ -385,10 +394,13 @@ class MANGOS_DLL_SPEC Creature : public Unit
void GetRespawnCoord(float &x, float &y, float &z, float* ori = NULL, float* dist =NULL) const; void GetRespawnCoord(float &x, float &y, float &z, float* ori = NULL, float* dist =NULL) const;
uint32 GetEquipmentId() const { return m_equipmentId; } uint32 GetEquipmentId() const { return m_equipmentId; }
bool isPet() const { return m_isPet; } CreatureSubtype GetSubtype() const { return m_subtype; }
bool isVehicle() const { return m_isVehicle; } bool isPet() const { return m_subtype == CREATURE_SUBTYPE_PET; }
bool isVehicle() const { return m_subtype == CREATURE_SUBTYPE_VEHICLE; }
bool isTotem() const { return m_subtype == CREATURE_SUBTYPE_TOTEM; }
bool isTemporarySummon() const { return m_subtype == CREATURE_SUBTYPE_TEMPORARY_SUMMON; }
void SetCorpseDelay(uint32 delay) { m_corpseDelay = delay; } void SetCorpseDelay(uint32 delay) { m_corpseDelay = delay; }
bool isTotem() const { return m_isTotem; }
bool isRacialLeader() const { return GetCreatureInfo()->RacialLeader; } bool isRacialLeader() const { return GetCreatureInfo()->RacialLeader; }
bool isCivilian() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN; } bool isCivilian() const { return GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN; }
bool canWalk() const { return GetCreatureInfo()->InhabitType & INHABIT_GROUND; } bool canWalk() const { return GetCreatureInfo()->InhabitType & INHABIT_GROUND; }
@ -628,9 +640,7 @@ class MANGOS_DLL_SPEC Creature : public Unit
uint32 m_corpseDelay; // (secs) delay between death and corpse disappearance uint32 m_corpseDelay; // (secs) delay between death and corpse disappearance
float m_respawnradius; float m_respawnradius;
bool m_isPet; // set only in Pet::Pet CreatureSubtype m_subtype; // set in Creatures subclasses for fast it detect without dynamic_cast use
bool m_isVehicle; // set only in Vehicle::Vehicle
bool m_isTotem; // set only in Totem::Totem
void RegenerateMana(); void RegenerateMana();
void RegenerateHealth(); void RegenerateHealth();
MovementGeneratorType m_defaultMovementType; MovementGeneratorType m_defaultMovementType;

View file

@ -38,11 +38,10 @@ char const* petTypeSuffix[MAX_PET_TYPE] =
}; };
Pet::Pet(PetType type) : Pet::Pet(PetType type) :
Creature(), m_removed(false), m_petType(type), m_happinessTimer(7500), m_duration(0), m_resetTalentsCost(0), Creature(CREATURE_SUBTYPE_PET), m_removed(false), m_petType(type), m_happinessTimer(7500), m_duration(0), m_resetTalentsCost(0),
m_bonusdamage(0), m_resetTalentsTime(0), m_usedTalentCount(0), m_auraUpdateMask(0), m_loading(false), m_bonusdamage(0), m_resetTalentsTime(0), m_usedTalentCount(0), m_auraUpdateMask(0), m_loading(false),
m_declinedname(NULL), m_petModeFlags(PET_MODE_DEFAULT) m_declinedname(NULL), m_petModeFlags(PET_MODE_DEFAULT)
{ {
m_isPet = true;
m_name = "Pet"; m_name = "Pet";
m_regenTimer = 4000; m_regenTimer = 4000;

View file

@ -94,11 +94,12 @@ void PointMovementGenerator<Creature>::MovementInform(Creature &unit)
if (unit.AI()) if (unit.AI())
unit.AI()->MovementInform(POINT_MOTION_TYPE, id); unit.AI()->MovementInform(POINT_MOTION_TYPE, id);
if (TemporarySummon* pSummon = dynamic_cast<TemporarySummon*>(&unit)) if (unit.isTemporarySummon())
{ {
if (Unit* pSummoner = pSummon->GetSummoner()) TemporarySummon* pSummon = (TemporarySummon*)(&unit);
if (IS_CREATURE_GUID(pSummon->GetSummonerGUID()))
{ {
if (pSummoner->GetTypeId() == TYPEID_UNIT) if (Unit* pSummoner = pSummon->GetSummoner())
{ {
if (((Creature*)pSummoner)->AI()) if (((Creature*)pSummoner)->AI())
((Creature*)pSummoner)->AI()->SummonedMovementInform(&unit, POINT_MOTION_TYPE, id); ((Creature*)pSummoner)->AI()->SummonedMovementInform(&unit, POINT_MOTION_TYPE, id);

View file

@ -22,7 +22,7 @@
#include "CreatureAI.h" #include "CreatureAI.h"
TemporarySummon::TemporarySummon( uint64 summoner ) : TemporarySummon::TemporarySummon( uint64 summoner ) :
Creature(), m_type(TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN), m_timer(0), m_lifetime(0), m_summoner(summoner) Creature(CREATURE_SUBTYPE_TEMPORARY_SUMMON), m_type(TEMPSUMMON_TIMED_OR_CORPSE_DESPAWN), m_timer(0), m_lifetime(0), m_summoner(summoner)
{ {
} }

View file

@ -31,6 +31,7 @@ class TemporarySummon : public Creature
void Summon(TempSummonType type, uint32 lifetime); void Summon(TempSummonType type, uint32 lifetime);
void MANGOS_DLL_SPEC UnSummon(); void MANGOS_DLL_SPEC UnSummon();
void SaveToDB(); void SaveToDB();
uint64 GetSummonerGUID() const { return m_summoner ; }
Unit* GetSummoner() const { return m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL; } Unit* GetSummoner() const { return m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL; }
private: private:
TempSummonType m_type; TempSummonType m_type;

View file

@ -24,9 +24,8 @@
#include "ObjectMgr.h" #include "ObjectMgr.h"
#include "SpellMgr.h" #include "SpellMgr.h"
Totem::Totem() : Creature() Totem::Totem() : Creature(CREATURE_SUBTYPE_TOTEM)
{ {
m_isTotem = true;
m_duration = 0; m_duration = 0;
m_type = TOTEM_PASSIVE; m_type = TOTEM_PASSIVE;
} }

View file

@ -23,9 +23,8 @@
#include "Unit.h" #include "Unit.h"
#include "Util.h" #include "Util.h"
Vehicle::Vehicle() : Creature(), m_vehicleId(0) Vehicle::Vehicle() : Creature(CREATURE_SUBTYPE_VEHICLE), m_vehicleId(0)
{ {
m_isVehicle = true;
m_updateFlag = (UPDATEFLAG_LIVING | UPDATEFLAG_HAS_POSITION | UPDATEFLAG_VEHICLE); m_updateFlag = (UPDATEFLAG_LIVING | UPDATEFLAG_HAS_POSITION | UPDATEFLAG_VEHICLE);
} }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9231" #define REVISION_NR "9232"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__