Core/ObjectMgr: Refactor sCreatureModelStorage

This commit is contained in:
leak
2011-04-28 22:11:45 +02:00
parent 6a431f745c
commit 85a1e9e7ab
8 changed files with 112 additions and 106 deletions
+12 -16
View File
@@ -299,18 +299,16 @@ bool Creature::InitEntry(uint32 Entry, uint32 /*team*/, const CreatureData *data
return false;
}
uint32 display_id = sObjectMgr->ChooseDisplayId(0, GetCreatureInfo(), data);
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(display_id);
uint32 displayID = sObjectMgr->ChooseDisplayId(0, GetCreatureInfo(), data);
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(displayID);
if (!minfo) // Cancel load if no model defined
{
sLog->outErrorDb("Creature (Entry: %u) has no model defined in table `creature_template`, can't load. ",Entry);
return false;
}
display_id = minfo->modelid; // it can be different (for another gender)
SetDisplayId(display_id);
SetNativeDisplayId(display_id);
SetDisplayId(displayID);
SetNativeDisplayId(displayID);
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
// Load creature equipment
@@ -780,13 +778,12 @@ bool Creature::Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry,
}
LoadCreaturesAddon();
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(GetNativeDisplayId());
uint32 displayID = 0;
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(displayID = GetNativeDisplayId());
if (minfo && !isTotem()) // Cancel load if no model defined or if totem
{
uint32 display_id = minfo->modelid; // it can be different (for another gender)
SetDisplayId(display_id);
SetNativeDisplayId(display_id);
SetDisplayId(displayID);
SetNativeDisplayId(displayID);
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
}
@@ -1620,13 +1617,12 @@ void Creature::Respawn(bool force)
else
setDeathState(JUST_ALIVED);
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(GetNativeDisplayId());
uint32 displayID = 0;
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(displayID = GetNativeDisplayId());
if (minfo) // Cancel load if no model defined
{
uint32 display_id = minfo->modelid; // it can be different (for another gender)
SetDisplayId(display_id);
SetNativeDisplayId(display_id);
SetDisplayId(displayID);
SetNativeDisplayId(displayID);
SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);
}
+3 -1
View File
@@ -281,13 +281,15 @@ struct CreatureDataAddon
struct CreatureModelInfo
{
uint32 modelid;
float bounding_radius;
float combat_reach;
uint8 gender;
uint32 modelid_other_gender;
};
// Benchmarked: Faster than std::map (insert/find)
typedef UNORDERED_MAP<uint16, CreatureModelInfo> CreatureModelContainer;
enum InhabitTypeValues
{
INHABIT_GROUND = 1,
+10 -12
View File
@@ -57,34 +57,32 @@ void Totem::InitStats(uint32 duration)
CreatureInfo const *cinfo = GetCreatureInfo();
if (m_owner->GetTypeId() == TYPEID_PLAYER && cinfo)
{
uint32 display_id = sObjectMgr->ChooseDisplayId(m_owner->ToPlayer()->GetTeam(), cinfo);
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(display_id);
if (minfo)
display_id = minfo->modelid;
uint32 displayID = sObjectMgr->ChooseDisplayId(m_owner->ToPlayer()->GetTeam(), cinfo);
CreatureModelInfo const *minfo = sObjectMgr->GetCreatureModelRandomGender(displayID);
switch (m_owner->ToPlayer()->GetTeam())
{
case ALLIANCE:
display_id = cinfo->Modelid1;
displayID = cinfo->Modelid1;
break;
case HORDE:
if (cinfo->Modelid3)
display_id = cinfo->Modelid3;
displayID = cinfo->Modelid3;
else
display_id = cinfo->Modelid1;
displayID = cinfo->Modelid1;
switch (((Player*)m_owner)->getRace())
{
case RACE_ORC:
if (cinfo->Modelid2)
display_id = cinfo->Modelid2;
displayID = cinfo->Modelid2;
else
display_id = cinfo->Modelid1;
displayID = cinfo->Modelid1;
break;
case RACE_TROLL:
if (cinfo->Modelid4)
display_id = cinfo->Modelid4;
displayID = cinfo->Modelid4;
else
display_id = cinfo->Modelid1;
displayID = cinfo->Modelid1;
break;
default:
break;
@@ -93,7 +91,7 @@ void Totem::InitStats(uint32 duration)
default:
break;
}
SetDisplayId(display_id);
SetDisplayId(displayID);
}
// Get spell casted by totem