diff options
| author | Spp <spp@jorge.gr> | 2011-08-04 14:27:10 +0200 |
|---|---|---|
| committer | Spp <spp@jorge.gr> | 2011-08-04 14:27:10 +0200 |
| commit | 473f3410123590bf23d61ab8fbb773654228bb6b (patch) | |
| tree | add7aca55ca14b8124af2cdf5477729e5c8eca58 /src | |
| parent | 1c882084f3b512677c8e90ffdd58d608be051b6a (diff) | |
Core/GameEvent: Minor code optimization. (Also cosmetic changes in other unrelated files)
Diffstat (limited to 'src')
| -rwxr-xr-x | src/server/game/Conditions/ConditionMgr.cpp | 131 | ||||
| -rwxr-xr-x | src/server/game/Conditions/ConditionMgr.h | 31 | ||||
| -rwxr-xr-x | src/server/game/Conditions/DisableMgr.cpp | 11 | ||||
| -rwxr-xr-x | src/server/game/Events/GameEventMgr.cpp | 53 | ||||
| -rwxr-xr-x | src/server/game/Events/GameEventMgr.h | 12 |
5 files changed, 119 insertions, 119 deletions
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index 4067d5fc7de..b45a870ee83 100755 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -167,42 +167,42 @@ bool Condition::Meets(Player* player, Unit* invoker) condMeets = !player->HasItemCount(mConditionValue1, 1, mConditionValue2 ? true : false); break; case CONDITION_LEVEL: + { + switch (mConditionValue2) { - switch (mConditionValue2) - { - case LVL_COND_EQ: - condMeets = player->getLevel() == mConditionValue1; - break; - case LVL_COND_HIGH: - condMeets = player->getLevel() > mConditionValue1; - break; - case LVL_COND_LOW: - condMeets = player->getLevel() < mConditionValue1; - break; - case LVL_COND_HIGH_EQ: - condMeets = player->getLevel() >= mConditionValue1; - break; - case LVL_COND_LOW_EQ: - condMeets = player->getLevel() <= mConditionValue1; - break; - } - break; + case LVL_COND_EQ: + condMeets = player->getLevel() == mConditionValue1; + break; + case LVL_COND_HIGH: + condMeets = player->getLevel() > mConditionValue1; + break; + case LVL_COND_LOW: + condMeets = player->getLevel() < mConditionValue1; + break; + case LVL_COND_HIGH_EQ: + condMeets = player->getLevel() >= mConditionValue1; + break; + case LVL_COND_LOW_EQ: + condMeets = player->getLevel() <= mConditionValue1; + break; } + break; + } case CONDITION_DRUNKENSTATE: - { - condMeets = (uint32)Player::GetDrunkenstateByValue(player->GetDrunkValue()) >= mConditionValue1; - break; - } + { + condMeets = (uint32)Player::GetDrunkenstateByValue(player->GetDrunkValue()) >= mConditionValue1; + break; + } case CONDITION_NEAR_CREATURE: - { - condMeets = GetClosestCreatureWithEntry(player, mConditionValue1, (float)mConditionValue2) ? true : false; - break; - } + { + condMeets = GetClosestCreatureWithEntry(player, mConditionValue1, (float)mConditionValue2) ? true : false; + break; + } case CONDITION_NEAR_GAMEOBJECT: - { - condMeets = GetClosestGameObjectWithEntry(player, mConditionValue1, (float)mConditionValue2) ? true : false; - break; - } + { + condMeets = GetClosestGameObjectWithEntry(player, mConditionValue1, (float)mConditionValue2) ? true : false; + break; + } default: condMeets = false; refId = 0; @@ -382,7 +382,7 @@ void ConditionMgr::LoadConditions(bool isReload) if (!result) { - sLog->outErrorDb(">> Loaded 0 conditions. DB table `groups` is empty!"); + sLog->outErrorDb(">> Loaded 0 conditions. DB table `conditions` is empty!"); sLog->outString(); return; } @@ -979,40 +979,32 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond) break; } case CONDITION_SOURCE_TYPE_QUEST_ACCEPT: + if (!sObjectMgr->GetQuestTemplate(cond->mSourceEntry)) { - Quest const *Quest = sObjectMgr->GetQuestTemplate(cond->mSourceEntry); - if (!Quest) - { - sLog->outErrorDb("CONDITION_SOURCE_TYPE_QUEST_ACCEPT specifies non-existing quest (%u), skipped", cond->mSourceEntry); - return false; - } + sLog->outErrorDb("CONDITION_SOURCE_TYPE_QUEST_ACCEPT specifies non-existing quest (%u), skipped", cond->mSourceEntry); + return false; } break; case CONDITION_SOURCE_TYPE_QUEST_SHOW_MARK: + if (!sObjectMgr->GetQuestTemplate(cond->mSourceEntry)) { - Quest const *Quest = sObjectMgr->GetQuestTemplate(cond->mSourceEntry); - if (!Quest) - { - sLog->outErrorDb("CONDITION_SOURCE_TYPE_QUEST_SHOW_MARK specifies non-existing quest (%u), skipped", cond->mSourceEntry); - return false; - } + sLog->outErrorDb("CONDITION_SOURCE_TYPE_QUEST_SHOW_MARK specifies non-existing quest (%u), skipped", cond->mSourceEntry); + return false; } break; case CONDITION_SOURCE_TYPE_VEHICLE_SPELL: + if (!sObjectMgr->GetCreatureTemplate(cond->mSourceGroup)) { - if (!sObjectMgr->GetCreatureTemplate(cond->mSourceGroup)) - { - sLog->outErrorDb("SourceEntry %u in `condition` table, does not exist in `creature_template`, ignoring.", cond->mSourceGroup); - return false; - } - SpellInfo const* spellProto = sSpellMgr->GetSpellInfo(cond->mSourceEntry); - if (!spellProto) - { - sLog->outErrorDb("SourceEntry %u in `condition` table, does not exist in `spell.dbc`, ignoring.", cond->mSourceEntry); - return false; - } - break; + sLog->outErrorDb("SourceEntry %u in `condition` table, does not exist in `creature_template`, ignoring.", cond->mSourceGroup); + return false; + } + + if (!sSpellMgr->GetSpellInfo(cond->mSourceEntry)) + { + sLog->outErrorDb("SourceEntry %u in `condition` table, does not exist in `spell.dbc`, ignoring.", cond->mSourceEntry); + return false; } + break; case CONDITION_SOURCE_TYPE_GOSSIP_MENU: case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION: case CONDITION_SOURCE_TYPE_NONE: @@ -1138,8 +1130,7 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) case CONDITION_QUEST_NONE: case CONDITION_QUEST_COMPLETE: { - Quest const *Quest = sObjectMgr->GetQuestTemplate(cond->mConditionValue1); - if (!Quest) + if (!sObjectMgr->GetQuestTemplate(cond->mConditionValue1)) { sLog->outErrorDb("Quest condition specifies non-existing quest (%u), skipped", cond->mConditionValue1); return false; @@ -1341,23 +1332,23 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) break; } case CONDITION_LEVEL: + { + if (cond->mConditionValue2 >= LVL_COND_MAX) { - if (cond->mConditionValue2 >= LVL_COND_MAX) - { - sLog->outErrorDb("Level condition has invalid option (%u), skipped", cond->mConditionValue2); - return false; - } - break; + sLog->outErrorDb("Level condition has invalid option (%u), skipped", cond->mConditionValue2); + return false; } + break; + } case CONDITION_DRUNKENSTATE: + { + if (cond->mConditionValue1 > DRUNKEN_SMASHED) { - if (cond->mConditionValue1 > DRUNKEN_SMASHED) - { - sLog->outErrorDb("DrunkState condition has invalid state (%u), skipped", cond->mConditionValue1); - return false; - } - break; + sLog->outErrorDb("DrunkState condition has invalid state (%u), skipped", cond->mConditionValue1); + return false; } + break; + } case CONDITION_NEAR_CREATURE: { if (!sObjectMgr->GetCreatureTemplate(cond->mConditionValue1)) diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h index daa20e585ff..406ae5d88b2 100755 --- a/src/server/game/Conditions/ConditionMgr.h +++ b/src/server/game/Conditions/ConditionMgr.h @@ -20,6 +20,7 @@ #define TRINITY_CONDITIONMGR_H #include "LootMgr.h" +#include <ace/Singleton.h> class Player; class Unit; @@ -63,12 +64,12 @@ enum ConditionType enum LevelConditionType { - LVL_COND_EQ = 0, - LVL_COND_HIGH = 1, - LVL_COND_LOW = 2, - LVL_COND_HIGH_EQ = 3, - LVL_COND_LOW_EQ = 4, - LVL_COND_MAX = 5, + LVL_COND_EQ, + LVL_COND_HIGH, + LVL_COND_LOW, + LVL_COND_HIGH_EQ, + LVL_COND_LOW_EQ, + LVL_COND_MAX }; enum ConditionSourceType @@ -141,11 +142,12 @@ typedef std::map<uint32, ConditionList > ConditionReferenceMap;//only used for r class ConditionMgr { friend class ACE_Singleton<ConditionMgr, ACE_Null_Mutex>; - ConditionMgr(); - ~ConditionMgr(); - public: + private: + ConditionMgr(); + ~ConditionMgr(); + public: void LoadConditions(bool isReload = false); bool isConditionTypeValid(Condition* cond); ConditionList GetConditionReferences(uint32 refId); @@ -154,14 +156,7 @@ class ConditionMgr ConditionList GetConditionsForNotGroupedEntry(ConditionSourceType sType, uint32 uEntry); ConditionList GetConditionsForVehicleSpell(uint32 creatureID, uint32 spellID); - protected: - - ConditionMap m_ConditionMap; - ConditionReferenceMap m_ConditionReferenceMap; - VehicleSpellConditionMap m_VehicleSpellConditions; - private: - bool isSourceTypeValid(Condition* cond); bool addToLootTemplate(Condition* cond, LootTemplate* loot); bool addToGossipMenus(Condition* cond); @@ -189,6 +184,10 @@ class ConditionMgr void Clean(); // free up resources std::list<Condition*> m_AllocatedMemory; // some garbage collection :) + + ConditionMap m_ConditionMap; + ConditionReferenceMap m_ConditionReferenceMap; + VehicleSpellConditionMap m_VehicleSpellConditions; }; #define sConditionMgr ACE_Singleton<ConditionMgr, ACE_Null_Mutex>::instance() diff --git a/src/server/game/Conditions/DisableMgr.cpp b/src/server/game/Conditions/DisableMgr.cpp index 07f97ac67bf..f8c6f6e8c1f 100755 --- a/src/server/game/Conditions/DisableMgr.cpp +++ b/src/server/game/Conditions/DisableMgr.cpp @@ -16,10 +16,10 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "SpellMgr.h" -#include "ObjectMgr.h" #include "DisableMgr.h" +#include "ObjectMgr.h" #include "OutdoorPvP.h" +#include "SpellMgr.h" #include "VMapManager2.h" DisableMgr::DisableMgr() @@ -77,7 +77,6 @@ void DisableMgr::LoadDisables() switch (type) { case DISABLE_TYPE_SPELL: - { if (!(sSpellMgr->GetSpellInfo(entry) || flags & SPELL_DISABLE_DEPRECATED_SPELL)) { sLog->outErrorDb("Spell entry %u from `disables` doesn't exist in dbc, skipped.", entry); @@ -104,7 +103,7 @@ void DisableMgr::LoadDisables() data.params[1].insert(atoi(tokens[i++])); } - } break; + break; // checked later case DISABLE_TYPE_QUEST: break; @@ -217,7 +216,7 @@ void DisableMgr::LoadDisables() m_DisableMap[type].insert(DisableTypeMap::value_type(entry, data)); ++total_count; - } + } while (result->NextRow()); sLog->outString(">> Loaded %u disables in %u ms", total_count, GetMSTimeDiffToNow(oldMSTime)); @@ -313,7 +312,7 @@ bool DisableMgr::IsDisabledFor(DisableType type, uint32 entry, Unit const* unit, uint8 disabledModes = itr->second.flags; Difficulty targetDifficulty = player->GetDifficulty(mapEntry->IsRaid()); GetDownscaledMapDifficultyData(entry, targetDifficulty); - switch(targetDifficulty) + switch (targetDifficulty) { case DUNGEON_DIFFICULTY_NORMAL: return disabledModes & DUNGEON_STATUSFLAG_NORMAL; diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index eccbf9b2950..42a849b92cf 100755 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -121,24 +121,24 @@ void GameEventMgr::StartInternalEvent(uint16 event_id) bool GameEventMgr::StartEvent(uint16 event_id, bool overwrite) { - if (mGameEvent[event_id].state == GAMEEVENT_NORMAL - || mGameEvent[event_id].state == GAMEEVENT_INTERNAL) + GameEventData &data = mGameEvent[event_id]; + if (data.state == GAMEEVENT_NORMAL || data.state == GAMEEVENT_INTERNAL) { AddActiveEvent(event_id); ApplyNewEvent(event_id); if (overwrite) { mGameEvent[event_id].start = time(NULL); - if (mGameEvent[event_id].end <= mGameEvent[event_id].start) - mGameEvent[event_id].end = mGameEvent[event_id].start+mGameEvent[event_id].length; + if (data.end <= data.start) + data.end = data.start + data.length; } return false; } else { - if (mGameEvent[event_id].state == GAMEEVENT_WORLD_INACTIVE) + if (data.state == GAMEEVENT_WORLD_INACTIVE) // set to conditions phase - mGameEvent[event_id].state = GAMEEVENT_WORLD_CONDITIONS; + data.state = GAMEEVENT_WORLD_CONDITIONS; // add to active events AddActiveEvent(event_id); @@ -161,27 +161,28 @@ bool GameEventMgr::StartEvent(uint16 event_id, bool overwrite) void GameEventMgr::StopEvent(uint16 event_id, bool overwrite) { - bool serverwide_evt = mGameEvent[event_id].state != GAMEEVENT_NORMAL && mGameEvent[event_id].state != GAMEEVENT_INTERNAL; + GameEventData &data = mGameEvent[event_id]; + bool serverwide_evt = data.state != GAMEEVENT_NORMAL && data.state != GAMEEVENT_INTERNAL; RemoveActiveEvent(event_id); UnApplyEvent(event_id); if (overwrite && !serverwide_evt) { - mGameEvent[event_id].start = time(NULL) - mGameEvent[event_id].length * MINUTE; - if (mGameEvent[event_id].end <= mGameEvent[event_id].start) - mGameEvent[event_id].end = mGameEvent[event_id].start+mGameEvent[event_id].length; + data.start = time(NULL) - data.length * MINUTE; + if (data.end <= data.start) + data.end = data.start + data.length; } else if (serverwide_evt) { // if finished world event, then only gm command can stop it - if (overwrite || mGameEvent[event_id].state != GAMEEVENT_WORLD_FINISHED) + if (overwrite || data.state != GAMEEVENT_WORLD_FINISHED) { // reset conditions - mGameEvent[event_id].nextstart = 0; - mGameEvent[event_id].state = GAMEEVENT_WORLD_INACTIVE; - std::map<uint32 /*condition id*/, GameEventFinishCondition>::iterator itr; - for (itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr) + data.nextstart = 0; + data.state = GAMEEVENT_WORLD_INACTIVE; + GameEventConditionMap::iterator itr; + for (itr = data.conditions.begin(); itr != data.conditions.end(); ++itr) itr->second.done = 0; SQLTransaction trans = CharacterDatabase.BeginTransaction(); @@ -696,7 +697,7 @@ void GameEventMgr::LoadFromDB() continue; } - std::map<uint32, GameEventFinishCondition>::iterator itr = mGameEvent[event_id].conditions.find(condition); + GameEventConditionMap::iterator itr = mGameEvent[event_id].conditions.find(condition); if (itr != mGameEvent[event_id].conditions.end()) { itr->second.done = fields[2].GetFloat(); @@ -962,20 +963,26 @@ uint32 GameEventMgr::StartSystem() // return the next void GameEventMgr::StartArenaSeason() { - QueryResult result = WorldDatabase.PQuery("SELECT eventEntry FROM game_event_arena_seasons WHERE season = '%i'", sWorld->getIntConfig(CONFIG_ARENA_SEASON_ID)); + uint8 season = sWorld->getIntConfig(CONFIG_ARENA_SEASON_ID); + QueryResult result = WorldDatabase.PQuery("SELECT eventEntry FROM game_event_arena_seasons WHERE season = '%i'", season); if (!result) { - sLog->outError("ArenaSeason (%i) must be an existant Arena Season", sWorld->getIntConfig(CONFIG_ARENA_SEASON_ID)); + sLog->outError("ArenaSeason (%u) must be an existant Arena Season", season); return; } Field *fields = result->Fetch(); - uint16 eventId = fields[0].GetUInt16(); + if (eventId >= mGameEvent.size()) + { + sLog->outError("EventEntry %u for ArenaSeason (%u) does not exists", eventId, season); + return; + } + StartEvent(eventId, true); - sLog->outString("Arena Season %i started...", sWorld->getIntConfig(CONFIG_ARENA_SEASON_ID)); + sLog->outString("Arena Season %u started...", season); sLog->outString(); } @@ -1512,7 +1519,7 @@ void GameEventMgr::HandleQuestComplete(uint32 quest_id) // not in correct phase, return if (mGameEvent[event_id].state != GAMEEVENT_WORLD_CONDITIONS) return; - std::map<uint32, GameEventFinishCondition>::iterator citr = mGameEvent[event_id].conditions.find(condition); + GameEventConditionMap::iterator citr = mGameEvent[event_id].conditions.find(condition); // condition is registered if (citr != mGameEvent[event_id].conditions.end()) { @@ -1552,7 +1559,7 @@ void GameEventMgr::HandleQuestComplete(uint32 quest_id) bool GameEventMgr::CheckOneGameEventConditions(uint16 event_id) { - for (std::map<uint32, GameEventFinishCondition>::iterator itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr) + for (GameEventConditionMap::const_iterator itr = mGameEvent[event_id].conditions.begin(); itr != mGameEvent[event_id].conditions.end(); ++itr) if (itr->second.done < itr->second.reqNum) // return false if a condition doesn't match return false; @@ -1585,7 +1592,7 @@ void GameEventMgr::SaveWorldEventStateToDB(uint16 event_id) void GameEventMgr::SendWorldStateUpdate(Player* plr, uint16 event_id) { - std::map<uint32, GameEventFinishCondition>::iterator itr; + GameEventConditionMap::const_iterator itr; for (itr = mGameEvent[event_id].conditions.begin(); itr !=mGameEvent[event_id].conditions.end(); ++itr) { if (itr->second.done_world_state) diff --git a/src/server/game/Events/GameEventMgr.h b/src/server/game/Events/GameEventMgr.h index 80cd8262515..7337110fd65 100755 --- a/src/server/game/Events/GameEventMgr.h +++ b/src/server/game/Events/GameEventMgr.h @@ -51,6 +51,8 @@ struct GameEventQuestToEventConditionNum float num; }; +typedef std::map<uint32 /*condition id*/, GameEventFinishCondition> GameEventConditionMap; + struct GameEventData { GameEventData() : start(1), end(0), nextstart(0), occurence(0), length(0), holiday_id(HOLIDAY_NONE), state(GAMEEVENT_NORMAL) {} @@ -61,7 +63,7 @@ struct GameEventData uint32 length; // length of the event (minutes) after finishing all conditions HolidayIds holiday_id; GameEventState state; // state of the game event, these are saved into the game_event table on change! - std::map<uint32 /*condition id*/, GameEventFinishCondition> conditions; // conditions to finish + GameEventConditionMap conditions; // conditions to finish std::set<uint16 /*gameevent id*/> prerequisite_events; // events that must be completed before starting this event std::string description; @@ -91,10 +93,12 @@ class Creature; class GameEventMgr { friend class ACE_Singleton<GameEventMgr, ACE_Null_Mutex>; - GameEventMgr(); - public: + + private: + GameEventMgr(); ~GameEventMgr() {}; + public: typedef std::set<uint16> ActiveEvents; typedef std::vector<GameEventData> GameEventDataMap; ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; } @@ -134,7 +138,7 @@ class GameEventMgr bool hasGameObjectQuestActiveEventExcept(uint32 quest_id, uint16 event_id); bool hasCreatureActiveEventExcept(uint32 creature_guid, uint16 event_id); bool hasGameObjectActiveEventExcept(uint32 go_guid, uint16 event_id); -protected: + typedef std::list<uint32> GuidList; typedef std::list<uint32> IdList; typedef std::vector<GuidList> GameEventGuidMap; |
