changes in creature base stats storage
* speedup stats searching * no more default stat generation for each class-level pair, there is only one default stat * CreatureBaseStats does not contain level and class --HG-- branch : trunk
This commit is contained in:
@@ -1083,7 +1083,6 @@ void Creature::SelectLevel(const CreatureInfo *cinfo)
|
|||||||
SetLevel(level);
|
SetLevel(level);
|
||||||
|
|
||||||
CreatureBaseStats const* stats = objmgr.GetCreatureBaseStats(level, cinfo->unit_class);
|
CreatureBaseStats const* stats = objmgr.GetCreatureBaseStats(level, cinfo->unit_class);
|
||||||
assert(stats); // should not be null
|
|
||||||
|
|
||||||
// health
|
// health
|
||||||
float healthmod = _GetHealthMod(rank);
|
float healthmod = _GetHealthMod(rank);
|
||||||
|
|||||||
+1
-3
@@ -172,8 +172,6 @@ struct CreatureInfo
|
|||||||
// Defines base stats for creatures (used to calculate HP/mana/armor).
|
// Defines base stats for creatures (used to calculate HP/mana/armor).
|
||||||
struct CreatureBaseStats
|
struct CreatureBaseStats
|
||||||
{
|
{
|
||||||
uint8 Level;
|
|
||||||
uint8 Class;
|
|
||||||
uint32 BaseHealth[MAX_CREATURE_BASE_HP];
|
uint32 BaseHealth[MAX_CREATURE_BASE_HP];
|
||||||
uint32 BaseMana;
|
uint32 BaseMana;
|
||||||
uint32 BaseArmor;
|
uint32 BaseArmor;
|
||||||
@@ -202,7 +200,7 @@ struct CreatureBaseStats
|
|||||||
static CreatureBaseStats const* GetBaseStats(uint8 level, uint8 unitClass);
|
static CreatureBaseStats const* GetBaseStats(uint8 level, uint8 unitClass);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<CreatureBaseStats> CreatureBaseStatsList;
|
typedef UNORDERED_MAP<uint16, CreatureBaseStats> CreatureBaseStatsMap;
|
||||||
|
|
||||||
struct CreatureLocale
|
struct CreatureLocale
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#define PAIR64_HIPART(x) (uint32)((uint64(x) >> 32) & UI64LIT(0x00000000FFFFFFFF))
|
#define PAIR64_HIPART(x) (uint32)((uint64(x) >> 32) & UI64LIT(0x00000000FFFFFFFF))
|
||||||
#define PAIR64_LOPART(x) (uint32)(uint64(x) & UI64LIT(0x00000000FFFFFFFF))
|
#define PAIR64_LOPART(x) (uint32)(uint64(x) & UI64LIT(0x00000000FFFFFFFF))
|
||||||
|
|
||||||
|
#define MAKE_PAIR16(l, h) uint16( uint8(l) | ( uint16(h) << 8 ) )
|
||||||
#define MAKE_PAIR32(l, h) uint32( uint16(l) | ( uint32(h) << 16 ) )
|
#define MAKE_PAIR32(l, h) uint32( uint16(l) | ( uint32(h) << 16 ) )
|
||||||
#define PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF)
|
#define PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF)
|
||||||
#define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF)
|
#define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF)
|
||||||
|
|||||||
+30
-32
@@ -8922,14 +8922,23 @@ void ObjectMgr::RemoveGMTicket(uint64 ticketGuid, int64 source, bool permanently
|
|||||||
|
|
||||||
CreatureBaseStats const* ObjectMgr::GetCreatureBaseStats(uint8 level, uint8 unitClass)
|
CreatureBaseStats const* ObjectMgr::GetCreatureBaseStats(uint8 level, uint8 unitClass)
|
||||||
{
|
{
|
||||||
for (CreatureBaseStatsList::const_iterator it = m_creatureBaseStatsList.begin(); it != m_creatureBaseStatsList.end(); ++it)
|
CreatureBaseStatsMap::const_iterator it = m_creatureBaseStatsMap.find( MAKE_PAIR16(level,unitClass) );
|
||||||
{
|
|
||||||
CreatureBaseStats const& stats = (*it);
|
|
||||||
if (stats.Level == level && stats.Class == unitClass)
|
|
||||||
return &stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
if (it != m_creatureBaseStatsMap.end())
|
||||||
|
return &(it->second);
|
||||||
|
|
||||||
|
struct DefaultCreatureBaseStats : public CreatureBaseStats
|
||||||
|
{
|
||||||
|
DefaultCreatureBaseStats()
|
||||||
|
{
|
||||||
|
BaseArmor = 1;
|
||||||
|
for (uint8 j = 0; j < MAX_CREATURE_BASE_HP; ++j)
|
||||||
|
BaseHealth[j] = 1;
|
||||||
|
BaseMana = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
static const DefaultCreatureBaseStats def_stats;
|
||||||
|
return &def_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectMgr::LoadCreatureClassLevelStats()
|
void ObjectMgr::LoadCreatureClassLevelStats()
|
||||||
@@ -8951,36 +8960,38 @@ void ObjectMgr::LoadCreatureClassLevelStats()
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
Field *fields = result->Fetch();
|
Field *fields = result->Fetch();
|
||||||
CreatureBaseStats stats = CreatureBaseStats();
|
|
||||||
stats.Level = fields[0].GetUInt32();
|
uint8 Level = fields[0].GetUInt32();
|
||||||
stats.Class = fields[1].GetUInt8();
|
uint8 Class = fields[1].GetUInt8();
|
||||||
|
|
||||||
|
CreatureBaseStats stats;
|
||||||
for (uint8 i = 0; i < MAX_CREATURE_BASE_HP; ++i)
|
for (uint8 i = 0; i < MAX_CREATURE_BASE_HP; ++i)
|
||||||
stats.BaseHealth[i] = fields[i + 2].GetUInt32();
|
stats.BaseHealth[i] = fields[i + 2].GetUInt32();
|
||||||
stats.BaseMana = fields[5].GetUInt32();
|
stats.BaseMana = fields[5].GetUInt32();
|
||||||
stats.BaseArmor = fields[6].GetUInt32();
|
stats.BaseArmor = fields[6].GetUInt32();
|
||||||
|
|
||||||
if (stats.Level > STRONG_MAX_LEVEL)
|
if (Level > STRONG_MAX_LEVEL)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Creature base stats for class %u has invalid level %u (max is %u) - set to %u",
|
sLog.outErrorDb("Creature base stats for class %u has invalid level %u (max is %u) - set to %u",
|
||||||
stats.Class, stats.Level, STRONG_MAX_LEVEL, STRONG_MAX_LEVEL);
|
Class, Level, STRONG_MAX_LEVEL, STRONG_MAX_LEVEL);
|
||||||
stats.Level = STRONG_MAX_LEVEL;
|
Level = STRONG_MAX_LEVEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stats.Class || ((1 << (stats.Class - 1)) & CLASSMASK_ALL_CREATURES) == 0)
|
if (!Class || ((1 << (Class - 1)) & CLASSMASK_ALL_CREATURES) == 0)
|
||||||
sLog.outErrorDb("Creature base stats for level %u has invalid class %u",
|
sLog.outErrorDb("Creature base stats for level %u has invalid class %u",
|
||||||
stats.Level, stats.Class);
|
Level, Class);
|
||||||
|
|
||||||
for (uint8 i = 0; i < MAX_CREATURE_BASE_HP; ++i)
|
for (uint8 i = 0; i < MAX_CREATURE_BASE_HP; ++i)
|
||||||
{
|
{
|
||||||
if (stats.BaseHealth[i] < 1)
|
if (stats.BaseHealth[i] < 1)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Creature base stats for class %u, level %u has invalid zero base HP[%u] - set to 1",
|
sLog.outErrorDb("Creature base stats for class %u, level %u has invalid zero base HP[%u] - set to 1",
|
||||||
stats.Class, stats.Level, i);
|
Class, Level, i);
|
||||||
stats.BaseHealth[i] = 1;
|
stats.BaseHealth[i] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_creatureBaseStatsList.push_back(stats);
|
m_creatureBaseStatsMap[MAKE_PAIR16(Level, Class)] = stats;
|
||||||
|
|
||||||
bar.step();
|
bar.step();
|
||||||
++counter;
|
++counter;
|
||||||
@@ -8993,22 +9004,9 @@ void ObjectMgr::LoadCreatureClassLevelStats()
|
|||||||
if (!info)
|
if (!info)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CreatureBaseStats const* stats = GetCreatureBaseStats(info->maxlevel, info->unit_class);
|
if (m_creatureBaseStatsMap.find( MAKE_PAIR16(info->maxlevel, info->unit_class) ) == m_creatureBaseStatsMap.end())
|
||||||
if (!stats)
|
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Missing base stats for creature template %u maxlevel %u, adding default values",
|
sLog.outErrorDb("Missing base stats for creature class %u maxlevel %u", info->unit_class, info->maxlevel);
|
||||||
info->Entry, info->maxlevel);
|
|
||||||
|
|
||||||
CreatureBaseStats new_stats = CreatureBaseStats();
|
|
||||||
|
|
||||||
new_stats.BaseArmor = 1;
|
|
||||||
for (uint8 j = 0; j < MAX_CREATURE_BASE_HP; ++j)
|
|
||||||
new_stats.BaseHealth[j] = 1;
|
|
||||||
new_stats.BaseMana = 0;
|
|
||||||
new_stats.Class = info->unit_class;
|
|
||||||
new_stats.Level = info->maxlevel;
|
|
||||||
|
|
||||||
m_creatureBaseStatsList.push_back(new_stats);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1061,7 +1061,7 @@ class ObjectMgr
|
|||||||
|
|
||||||
MailLevelRewardMap m_mailLevelRewardMap;
|
MailLevelRewardMap m_mailLevelRewardMap;
|
||||||
|
|
||||||
CreatureBaseStatsList m_creatureBaseStatsList;
|
CreatureBaseStatsMap m_creatureBaseStatsMap;
|
||||||
|
|
||||||
typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
|
typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
|
||||||
// PetLevelInfoMap[creature_id][level]
|
// PetLevelInfoMap[creature_id][level]
|
||||||
|
|||||||
Reference in New Issue
Block a user