diff options
author | silver1ce <none@none> | 2010-03-03 04:32:47 +0200 |
---|---|---|
committer | silver1ce <none@none> | 2010-03-03 04:32:47 +0200 |
commit | f748ea34e383b6c2ed508b6c088f997e642b9712 (patch) | |
tree | 075c578d10f4a6e434ef6403eec30c24555a9be5 /src | |
parent | 9e63454b6306c369a9a0b8c21fd4d87e6e9f5a98 (diff) |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/game/Creature.cpp | 1 | ||||
-rw-r--r-- | src/game/Creature.h | 4 | ||||
-rw-r--r-- | src/game/ObjectDefines.h | 1 | ||||
-rw-r--r-- | src/game/ObjectMgr.cpp | 62 | ||||
-rw-r--r-- | src/game/ObjectMgr.h | 2 |
5 files changed, 33 insertions, 37 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index d88dddedd0c..7aada79974d 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1083,7 +1083,6 @@ void Creature::SelectLevel(const CreatureInfo *cinfo) SetLevel(level); CreatureBaseStats const* stats = objmgr.GetCreatureBaseStats(level, cinfo->unit_class); - assert(stats); // should not be null // health float healthmod = _GetHealthMod(rank); diff --git a/src/game/Creature.h b/src/game/Creature.h index 57f7968e58d..d073901a13d 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -172,8 +172,6 @@ struct CreatureInfo // Defines base stats for creatures (used to calculate HP/mana/armor). struct CreatureBaseStats { - uint8 Level; - uint8 Class; uint32 BaseHealth[MAX_CREATURE_BASE_HP]; uint32 BaseMana; uint32 BaseArmor; @@ -202,7 +200,7 @@ struct CreatureBaseStats static CreatureBaseStats const* GetBaseStats(uint8 level, uint8 unitClass); }; -typedef std::vector<CreatureBaseStats> CreatureBaseStatsList; +typedef UNORDERED_MAP<uint16, CreatureBaseStats> CreatureBaseStatsMap; struct CreatureLocale { diff --git a/src/game/ObjectDefines.h b/src/game/ObjectDefines.h index 19277e4ff44..a4d53aeee96 100644 --- a/src/game/ObjectDefines.h +++ b/src/game/ObjectDefines.h @@ -28,6 +28,7 @@ #define PAIR64_HIPART(x) (uint32)((uint64(x) >> 32) & 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 PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF) #define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF) diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index f6e15872d85..ca58d9d3eb2 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -8922,14 +8922,23 @@ void ObjectMgr::RemoveGMTicket(uint64 ticketGuid, int64 source, bool permanently CreatureBaseStats const* ObjectMgr::GetCreatureBaseStats(uint8 level, uint8 unitClass) { - for (CreatureBaseStatsList::const_iterator it = m_creatureBaseStatsList.begin(); it != m_creatureBaseStatsList.end(); ++it) - { - CreatureBaseStats const& stats = (*it); - if (stats.Level == level && stats.Class == unitClass) - return &stats; - } + CreatureBaseStatsMap::const_iterator it = m_creatureBaseStatsMap.find( MAKE_PAIR16(level,unitClass) ); - 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() @@ -8951,36 +8960,38 @@ void ObjectMgr::LoadCreatureClassLevelStats() do { Field *fields = result->Fetch(); - CreatureBaseStats stats = CreatureBaseStats(); - stats.Level = fields[0].GetUInt32(); - stats.Class = fields[1].GetUInt8(); + + uint8 Level = fields[0].GetUInt32(); + uint8 Class = fields[1].GetUInt8(); + + CreatureBaseStats stats; for (uint8 i = 0; i < MAX_CREATURE_BASE_HP; ++i) stats.BaseHealth[i] = fields[i + 2].GetUInt32(); stats.BaseMana = fields[5].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", - stats.Class, stats.Level, STRONG_MAX_LEVEL, STRONG_MAX_LEVEL); - stats.Level = STRONG_MAX_LEVEL; + Class, Level, STRONG_MAX_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", - stats.Level, stats.Class); + Level, Class); for (uint8 i = 0; i < MAX_CREATURE_BASE_HP; ++i) { if (stats.BaseHealth[i] < 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; } } - m_creatureBaseStatsList.push_back(stats); + m_creatureBaseStatsMap[MAKE_PAIR16(Level, Class)] = stats; bar.step(); ++counter; @@ -8993,22 +9004,9 @@ void ObjectMgr::LoadCreatureClassLevelStats() if (!info) continue; - CreatureBaseStats const* stats = GetCreatureBaseStats(info->maxlevel, info->unit_class); - if (!stats) + if (m_creatureBaseStatsMap.find( MAKE_PAIR16(info->maxlevel, info->unit_class) ) == m_creatureBaseStatsMap.end()) { - sLog.outErrorDb("Missing base stats for creature template %u maxlevel %u, adding default values", - 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); + sLog.outErrorDb("Missing base stats for creature class %u maxlevel %u", info->unit_class, info->maxlevel); } } diff --git a/src/game/ObjectMgr.h b/src/game/ObjectMgr.h index 524ad869dd0..3bb83e4a980 100644 --- a/src/game/ObjectMgr.h +++ b/src/game/ObjectMgr.h @@ -1061,7 +1061,7 @@ class ObjectMgr MailLevelRewardMap m_mailLevelRewardMap; - CreatureBaseStatsList m_creatureBaseStatsList; + CreatureBaseStatsMap m_creatureBaseStatsMap; typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap; // PetLevelInfoMap[creature_id][level] |