[7123] Cleanup in using STD's containers erase method.
[getmangos.git] / src / game / ObjectMgr.h
blobb8b75f0ba1de89a9e9a03e449155f12f552dd7b7
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _OBJECTMGR_H
20 #define _OBJECTMGR_H
22 #include "Log.h"
23 #include "Object.h"
24 #include "Bag.h"
25 #include "Creature.h"
26 #include "Player.h"
27 #include "DynamicObject.h"
28 #include "GameObject.h"
29 #include "Corpse.h"
30 #include "QuestDef.h"
31 #include "Path.h"
32 #include "ItemPrototype.h"
33 #include "NPCHandler.h"
34 #include "Database/DatabaseEnv.h"
35 #include "AuctionHouseObject.h"
36 #include "Mail.h"
37 #include "Map.h"
38 #include "ObjectAccessor.h"
39 #include "ObjectDefines.h"
40 #include "Policies/Singleton.h"
41 #include "Database/SQLStorage.h"
43 #include <string>
44 #include <map>
45 #include <limits>
47 extern SQLStorage sCreatureStorage;
48 extern SQLStorage sCreatureDataAddonStorage;
49 extern SQLStorage sCreatureInfoAddonStorage;
50 extern SQLStorage sCreatureModelStorage;
51 extern SQLStorage sEquipmentStorage;
52 extern SQLStorage sGOStorage;
53 extern SQLStorage sPageTextStore;
54 extern SQLStorage sItemStorage;
55 extern SQLStorage sInstanceTemplate;
57 class Group;
58 class Guild;
59 class ArenaTeam;
60 class Path;
61 class TransportPath;
62 class Item;
64 struct GameTele
66 float position_x;
67 float position_y;
68 float position_z;
69 float orientation;
70 uint32 mapId;
71 std::string name;
72 std::wstring wnameLow;
75 typedef UNORDERED_MAP<uint32, GameTele > GameTeleMap;
77 struct ScriptInfo
79 uint32 id;
80 uint32 delay;
81 uint32 command;
82 uint32 datalong;
83 uint32 datalong2;
84 int32 dataint;
85 float x;
86 float y;
87 float z;
88 float o;
91 typedef std::multimap<uint32, ScriptInfo> ScriptMap;
92 typedef std::map<uint32, ScriptMap > ScriptMapMap;
93 extern ScriptMapMap sQuestEndScripts;
94 extern ScriptMapMap sQuestStartScripts;
95 extern ScriptMapMap sSpellScripts;
96 extern ScriptMapMap sGameObjectScripts;
97 extern ScriptMapMap sEventScripts;
99 struct AreaTrigger
101 uint8 requiredLevel;
102 uint32 requiredItem;
103 uint32 requiredItem2;
104 uint32 heroicKey;
105 uint32 heroicKey2;
106 uint32 requiredQuest;
107 std::string requiredFailedText;
108 uint32 target_mapId;
109 float target_X;
110 float target_Y;
111 float target_Z;
112 float target_Orientation;
115 typedef std::set<uint32> CellGuidSet;
116 typedef std::map<uint32/*player guid*/,uint32/*instance*/> CellCorpseSet;
117 struct CellObjectGuids
119 CellGuidSet creatures;
120 CellGuidSet gameobjects;
121 CellCorpseSet corpses;
123 typedef UNORDERED_MAP<uint32/*cell_id*/,CellObjectGuids> CellObjectGuidsMap;
124 typedef UNORDERED_MAP<uint32/*(mapid,spawnMode) pair*/,CellObjectGuidsMap> MapObjectGuids;
126 typedef UNORDERED_MAP<uint64/*(instance,guid) pair*/,time_t> RespawnTimes;
129 // mangos string ranges
130 #define MIN_MANGOS_STRING_ID 1
131 #define MAX_MANGOS_STRING_ID 2000000000
132 #define MIN_DB_SCRIPT_STRING_ID MAX_MANGOS_STRING_ID
133 #define MAX_DB_SCRIPT_STRING_ID 2000010000
135 struct MangosStringLocale
137 std::vector<std::string> Content; // 0 -> default, i -> i-1 locale index
140 typedef UNORDERED_MAP<uint32,CreatureData> CreatureDataMap;
141 typedef UNORDERED_MAP<uint32,GameObjectData> GameObjectDataMap;
142 typedef UNORDERED_MAP<uint32,CreatureLocale> CreatureLocaleMap;
143 typedef UNORDERED_MAP<uint32,GameObjectLocale> GameObjectLocaleMap;
144 typedef UNORDERED_MAP<uint32,ItemLocale> ItemLocaleMap;
145 typedef UNORDERED_MAP<uint32,QuestLocale> QuestLocaleMap;
146 typedef UNORDERED_MAP<uint32,NpcTextLocale> NpcTextLocaleMap;
147 typedef UNORDERED_MAP<uint32,PageTextLocale> PageTextLocaleMap;
148 typedef UNORDERED_MAP<uint32,MangosStringLocale> MangosStringLocaleMap;
149 typedef UNORDERED_MAP<uint32,NpcOptionLocale> NpcOptionLocaleMap;
151 typedef std::multimap<uint32,uint32> QuestRelations;
153 struct PetLevelInfo
155 PetLevelInfo() : health(0), mana(0) { for(int i=0; i < MAX_STATS; ++i ) stats[i] = 0; }
157 uint16 stats[MAX_STATS];
158 uint16 health;
159 uint16 mana;
160 uint16 armor;
163 struct ReputationOnKillEntry
165 uint32 repfaction1;
166 uint32 repfaction2;
167 bool is_teamaward1;
168 uint32 reputation_max_cap1;
169 int32 repvalue1;
170 bool is_teamaward2;
171 uint32 reputation_max_cap2;
172 int32 repvalue2;
173 bool team_dependent;
176 struct PetCreateSpellEntry
178 uint32 spellid[4];
181 #define WEATHER_SEASONS 4
182 struct WeatherSeasonChances
184 uint32 rainChance;
185 uint32 snowChance;
186 uint32 stormChance;
189 struct WeatherZoneChances
191 WeatherSeasonChances data[WEATHER_SEASONS];
194 struct GraveYardData
196 uint32 safeLocId;
197 uint32 team;
199 typedef std::multimap<uint32,GraveYardData> GraveYardMap;
201 enum ConditionType
202 { // value1 value2 for the Condition enumed
203 CONDITION_NONE = 0, // 0 0
204 CONDITION_AURA = 1, // spell_id effindex
205 CONDITION_ITEM = 2, // item_id count
206 CONDITION_ITEM_EQUIPPED = 3, // item_id 0
207 CONDITION_ZONEID = 4, // zone_id 0
208 CONDITION_REPUTATION_RANK = 5, // faction_id min_rank
209 CONDITION_TEAM = 6, // player_team 0, (469 - Alliance 67 - Horde)
210 CONDITION_SKILL = 7, // skill_id skill_value
211 CONDITION_QUESTREWARDED = 8, // quest_id 0
212 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active.
213 CONDITION_AD_COMMISSION_AURA = 10, // 0 0, for condition true while one from AD ñommission aura active
214 CONDITION_NO_AURA = 11, // spell_id effindex
215 CONDITION_ACTIVE_EVENT = 12, // event_id
218 #define MAX_CONDITION 13 // maximum value in ConditionType enum
220 struct PlayerCondition
222 ConditionType condition; // additional condition type
223 uint32 value1; // data for the condition - see ConditionType definition
224 uint32 value2;
226 PlayerCondition(uint8 _condition = 0, uint32 _value1 = 0, uint32 _value2 = 0)
227 : condition(ConditionType(_condition)), value1(_value1), value2(_value2) {}
229 static bool IsValid(ConditionType condition, uint32 value1, uint32 value2);
230 // Checks correctness of values
231 bool Meets(Player const * APlayer) const; // Checks if the player meets the condition
232 bool operator == (PlayerCondition const& lc) const
234 return (lc.condition == condition && lc.value1 == value1 && lc.value2 == value2);
238 // NPC gossip text id
239 typedef UNORDERED_MAP<uint32, uint32> CacheNpcTextIdMap;
240 typedef std::list<GossipOption> CacheNpcOptionList;
242 typedef UNORDERED_MAP<uint32, VendorItemData> CacheVendorItemMap;
243 typedef UNORDERED_MAP<uint32, TrainerSpellData> CacheTrainerSpellMap;
245 enum SkillRangeType
247 SKILL_RANGE_LANGUAGE, // 300..300
248 SKILL_RANGE_LEVEL, // 1..max skill for level
249 SKILL_RANGE_MONO, // 1..1, grey monolite bar
250 SKILL_RANGE_RANK, // 1..skill for known rank
251 SKILL_RANGE_NONE, // 0..0 always
254 SkillRangeType GetSkillRangeType(SkillLineEntry const *pSkill, bool racial);
256 #define MAX_PLAYER_NAME 12 // max allowed by client name length
257 #define MAX_INTERNAL_PLAYER_NAME 15 // max server internal player name length ( > MAX_PLAYER_NAME for support declined names )
259 bool normalizePlayerName(std::string& name);
261 struct MANGOS_DLL_SPEC LanguageDesc
263 Language lang_id;
264 uint32 spell_id;
265 uint32 skill_id;
268 extern LanguageDesc lang_description[LANGUAGES_COUNT];
269 MANGOS_DLL_SPEC LanguageDesc const* GetLanguageDescByID(uint32 lang);
271 class PlayerDumpReader;
273 class ObjectMgr
275 friend class PlayerDumpReader;
277 public:
278 ObjectMgr();
279 ~ObjectMgr();
281 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
283 typedef std::set< Group * > GroupSet;
284 typedef std::set< Guild * > GuildSet;
286 typedef UNORDERED_MAP<uint32, ArenaTeam* > ArenaTeamMap;
288 typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
290 typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
292 typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
294 typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
296 typedef UNORDERED_MAP<uint32, WeatherZoneChances> WeatherZoneMap;
298 typedef UNORDERED_MAP<uint32, PetCreateSpellEntry> PetCreateSpellMap;
300 typedef std::vector<std::string> ScriptNameMap;
302 Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
303 Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
305 static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
307 void LoadGameobjectInfo();
308 void AddGameobjectInfo(GameObjectInfo *goinfo);
310 Group * GetGroupByLeader(const uint64 &guid) const;
311 void AddGroup(Group* group) { mGroupSet.insert( group ); }
312 void RemoveGroup(Group* group) { mGroupSet.erase( group ); }
314 Guild* GetGuildByLeader(uint64 const&guid) const;
315 Guild* GetGuildById(const uint32 GuildId) const;
316 Guild* GetGuildByName(const std::string& guildname) const;
317 std::string GetGuildNameById(const uint32 GuildId) const;
318 void AddGuild(Guild* guild) { mGuildSet.insert( guild ); }
319 void RemoveGuild(Guild* guild) { mGuildSet.erase( guild ); }
321 ArenaTeam* GetArenaTeamById(const uint32 arenateamid) const;
322 ArenaTeam* GetArenaTeamByName(const std::string& arenateamname) const;
323 ArenaTeam* GetArenaTeamByCaptain(uint64 const& guid) const;
324 void AddArenaTeam(ArenaTeam* arenaTeam);
325 void RemoveArenaTeam(ArenaTeam* arenaTeam);
326 ArenaTeamMap::iterator GetArenaTeamMapBegin() { return mArenaTeamMap.begin(); }
327 ArenaTeamMap::iterator GetArenaTeamMapEnd() { return mArenaTeamMap.end(); }
329 static CreatureInfo const *GetCreatureTemplate( uint32 id );
330 CreatureModelInfo const *GetCreatureModelInfo( uint32 modelid );
331 CreatureModelInfo const* GetCreatureModelRandomGender(uint32 display_id);
332 uint32 ChooseDisplayId(uint32 team, const CreatureInfo *cinfo, const CreatureData *data = NULL);
333 EquipmentInfo const *GetEquipmentInfo( uint32 entry );
334 static CreatureDataAddon const *GetCreatureAddon( uint32 lowguid )
336 return sCreatureDataAddonStorage.LookupEntry<CreatureDataAddon>(lowguid);
339 static CreatureDataAddon const *GetCreatureTemplateAddon( uint32 entry )
341 return sCreatureInfoAddonStorage.LookupEntry<CreatureDataAddon>(entry);
344 static ItemPrototype const* GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry<ItemPrototype>(id); }
346 static InstanceTemplate const* GetInstanceTemplate(uint32 map)
348 return sInstanceTemplate.LookupEntry<InstanceTemplate>(map);
351 Item* GetAItem(uint32 id)
353 ItemMap::const_iterator itr = mAitems.find(id);
354 if (itr != mAitems.end())
356 return itr->second;
358 return NULL;
360 void AddAItem(Item* it)
362 ASSERT( it );
363 ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end());
364 mAitems[it->GetGUIDLow()] = it;
366 bool RemoveAItem(uint32 id)
368 ItemMap::iterator i = mAitems.find(id);
369 if (i == mAitems.end())
371 return false;
373 mAitems.erase(i);
374 return true;
376 AuctionHouseObject * GetAuctionsMap( uint32 location );
378 //auction messages
379 void SendAuctionWonMail( AuctionEntry * auction );
380 void SendAuctionSalePendingMail( AuctionEntry * auction );
381 void SendAuctionSuccessfulMail( AuctionEntry * auction );
382 void SendAuctionExpiredMail( AuctionEntry * auction );
383 static uint32 GetAuctionCut( uint32 location, uint32 highBid );
384 static uint32 GetAuctionDeposit(uint32 location, uint32 time, Item *pItem);
385 static uint32 GetAuctionOutBid(uint32 currentBid);
387 PetLevelInfo const* GetPetLevelInfo(uint32 creature_id, uint32 level) const;
389 PlayerClassInfo const* GetPlayerClassInfo(uint32 class_) const
391 if(class_ >= MAX_CLASSES) return NULL;
392 return &playerClassInfo[class_];
394 void GetPlayerClassLevelInfo(uint32 class_,uint32 level, PlayerClassLevelInfo* info) const;
396 PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const
398 if(race >= MAX_RACES) return NULL;
399 if(class_ >= MAX_CLASSES) return NULL;
400 PlayerInfo const* info = &playerInfo[race][class_];
401 if(info->displayId_m==0 || info->displayId_f==0) return NULL;
402 return info;
404 void GetPlayerLevelInfo(uint32 race, uint32 class_,uint32 level, PlayerLevelInfo* info) const;
406 uint64 GetPlayerGUIDByName(std::string name) const;
407 bool GetPlayerNameByGUID(const uint64 &guid, std::string &name) const;
408 uint32 GetPlayerTeamByGUID(const uint64 &guid) const;
409 uint32 GetPlayerAccountIdByGUID(const uint64 &guid) const;
410 uint32 GetPlayerAccountIdByPlayerName(const std::string& name) const;
412 uint32 GetNearestTaxiNode( float x, float y, float z, uint32 mapid );
413 void GetTaxiPath( uint32 source, uint32 destination, uint32 &path, uint32 &cost);
414 uint16 GetTaxiMount( uint32 id, uint32 team );
415 void GetTaxiPathNodes( uint32 path, Path &pathnodes, std::vector<uint32>& mapIds );
416 void GetTransportPathNodes( uint32 path, TransportPath &pathnodes );
418 Quest const* GetQuestTemplate(uint32 quest_id) const
420 QuestMap::const_iterator itr = mQuestTemplates.find(quest_id);
421 return itr != mQuestTemplates.end() ? itr->second : NULL;
423 QuestMap const& GetQuestTemplates() const { return mQuestTemplates; }
425 uint32 GetQuestForAreaTrigger(uint32 Trigger_ID) const
427 QuestAreaTriggerMap::const_iterator itr = mQuestAreaTriggerMap.find(Trigger_ID);
428 if(itr != mQuestAreaTriggerMap.end())
429 return itr->second;
430 return 0;
432 bool IsTavernAreaTrigger(uint32 Trigger_ID) const { return mTavernAreaTriggerSet.count(Trigger_ID) != 0; }
433 bool IsGameObjectForQuests(uint32 entry) const { return mGameObjectForQuestSet.count(entry) != 0; }
434 bool IsGuildVaultGameObject(Player *player, uint64 guid) const
436 if(GameObject *go = ObjectAccessor::GetGameObject(*player, guid))
437 if(go->GetGoType() == GAMEOBJECT_TYPE_GUILD_BANK)
438 return true;
439 return false;
442 uint32 GetBattleMasterBG(uint32 entry) const
444 BattleMastersMap::const_iterator itr = mBattleMastersMap.find(entry);
445 if(itr != mBattleMastersMap.end())
446 return itr->second;
447 return 2; //BATTLEGROUND_WS - i will not add include only for constant usage!
450 void AddGossipText(GossipText *pGText);
451 GossipText *GetGossipText(uint32 Text_ID);
453 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
454 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
455 void LoadGraveyardZones();
456 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
458 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
460 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
461 if( itr != mAreaTriggers.end( ) )
462 return &itr->second;
463 return NULL;
466 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
467 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
469 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
471 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
473 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
474 if(itr != mRepOnKill.end())
475 return &itr->second;
476 return NULL;
479 PetCreateSpellEntry const* GetPetCreateSpellEntry(uint32 id) const
481 PetCreateSpellMap::const_iterator itr = mPetCreateSpell.find(id);
482 if(itr != mPetCreateSpell.end())
483 return &itr->second;
484 return NULL;
487 void LoadGuilds();
488 void LoadArenaTeams();
489 void LoadGroups();
490 void LoadQuests();
491 void LoadQuestRelations()
493 LoadGameobjectQuestRelations();
494 LoadGameobjectInvolvedRelations();
495 LoadCreatureQuestRelations();
496 LoadCreatureInvolvedRelations();
498 void LoadGameobjectQuestRelations();
499 void LoadGameobjectInvolvedRelations();
500 void LoadCreatureQuestRelations();
501 void LoadCreatureInvolvedRelations();
503 QuestRelations mGOQuestRelations;
504 QuestRelations mGOQuestInvolvedRelations;
505 QuestRelations mCreatureQuestRelations;
506 QuestRelations mCreatureQuestInvolvedRelations;
508 void LoadGameObjectScripts();
509 void LoadQuestEndScripts();
510 void LoadQuestStartScripts();
511 void LoadEventScripts();
512 void LoadSpellScripts();
514 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
515 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
516 void LoadDbScriptStrings();
517 void LoadPetCreateSpells();
518 void LoadCreatureLocales();
519 void LoadCreatureTemplates();
520 void LoadCreatures();
521 void LoadCreatureRespawnTimes();
522 void LoadCreatureAddons();
523 void LoadCreatureModelInfo();
524 void LoadEquipmentTemplates();
525 void LoadGameObjectLocales();
526 void LoadGameobjects();
527 void LoadGameobjectRespawnTimes();
528 void LoadItemPrototypes();
529 void LoadItemLocales();
530 void LoadQuestLocales();
531 void LoadNpcTextLocales();
532 void LoadPageTextLocales();
533 void LoadNpcOptionLocales();
534 void LoadInstanceTemplate();
536 void LoadGossipText();
538 void LoadAreaTriggerTeleports();
539 void LoadQuestAreaTriggers();
540 void LoadAreaTriggerScripts();
541 void LoadTavernAreaTriggers();
542 void LoadBattleMastersEntry();
543 void LoadGameObjectForQuests();
545 void LoadItemTexts();
546 void LoadPageTexts();
548 //load first auction items, because of check if item exists, when loading
549 void LoadAuctionItems();
550 void LoadAuctions();
551 void LoadPlayerInfo();
552 void LoadPetLevelInfo();
553 void LoadExplorationBaseXP();
554 void LoadPetNames();
555 void LoadPetNumber();
556 void LoadCorpses();
557 void LoadFishingBaseSkillLevel();
559 void LoadReputationOnKill();
561 void LoadWeatherZoneChances();
562 void LoadGameTele();
564 void LoadNpcOptions();
565 void LoadNpcTextId();
566 void LoadVendors();
567 void LoadTrainerSpell();
569 std::string GeneratePetName(uint32 entry);
570 uint32 GetBaseXP(uint32 level);
571 uint32 GetXPForLevel(uint32 level);
573 int32 GetFishingBaseSkillLevel(uint32 entry) const
575 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
576 return itr != mFishingBaseForArea.end() ? itr->second : 0;
579 void ReturnOrDeleteOldMails(bool serverUp);
581 void SetHighestGuids();
582 uint32 GenerateLowGuid(HighGuid guidhigh);
583 uint32 GenerateAuctionID();
584 uint32 GenerateMailID();
585 uint32 GenerateItemTextID();
586 uint32 GeneratePetNumber();
587 uint32 GenerateArenaTeamId();
588 uint32 GenerateGuildId();
590 uint32 CreateItemText(std::string text);
591 std::string GetItemText( uint32 id )
593 ItemTextMap::const_iterator itr = mItemTexts.find( id );
594 if ( itr != mItemTexts.end() )
595 return itr->second;
596 else
597 return "There is no info for this item";
600 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
601 ExclusiveQuestGroups mExclusiveQuestGroups;
603 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
605 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
606 if(itr != mWeatherZoneMap.end())
607 return &itr->second;
608 else
609 return NULL;
612 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
614 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
617 CreatureData const* GetCreatureData(uint32 guid) const
619 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
620 if(itr==mCreatureDataMap.end()) return NULL;
621 return &itr->second;
623 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
624 void DeleteCreatureData(uint32 guid);
625 CreatureLocale const* GetCreatureLocale(uint32 entry) const
627 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
628 if(itr==mCreatureLocaleMap.end()) return NULL;
629 return &itr->second;
631 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
633 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
634 if(itr==mGameObjectLocaleMap.end()) return NULL;
635 return &itr->second;
637 ItemLocale const* GetItemLocale(uint32 entry) const
639 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
640 if(itr==mItemLocaleMap.end()) return NULL;
641 return &itr->second;
643 QuestLocale const* GetQuestLocale(uint32 entry) const
645 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
646 if(itr==mQuestLocaleMap.end()) return NULL;
647 return &itr->second;
649 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
651 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
652 if(itr==mNpcTextLocaleMap.end()) return NULL;
653 return &itr->second;
655 PageTextLocale const* GetPageTextLocale(uint32 entry) const
657 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
658 if(itr==mPageTextLocaleMap.end()) return NULL;
659 return &itr->second;
661 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
663 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
664 if(itr==mNpcOptionLocaleMap.end()) return NULL;
665 return &itr->second;
668 GameObjectData const* GetGOData(uint32 guid) const
670 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
671 if(itr==mGameObjectDataMap.end()) return NULL;
672 return &itr->second;
674 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
675 void DeleteGOData(uint32 guid);
677 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
679 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
680 if(itr==mMangosStringLocaleMap.end()) return NULL;
681 return &itr->second;
683 const char *GetMangosString(int32 entry, int locale_idx) const;
684 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
685 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
686 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
688 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
689 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
691 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
692 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
693 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
694 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
695 void DeleteRespawnTimeForInstance(uint32 instance);
697 // grid objects
698 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
699 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
700 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
701 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
703 // reserved names
704 void LoadReservedPlayersNames();
705 bool IsReservedName(const std::string& name) const
707 return m_ReservedNames.find(name) != m_ReservedNames.end();
710 // name with valid structure and symbols
711 static bool IsValidName( const std::string& name, bool create = false );
712 static bool IsValidCharterName( const std::string& name );
713 static bool IsValidPetName( const std::string& name );
715 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
717 int GetIndexForLocale(LocaleConstant loc);
718 LocaleConstant GetLocaleForIndex(int i);
719 // guild bank tabs
720 uint32 GetGuildBankTabPrice(uint8 Index) const { return Index < GUILD_BANK_MAX_TABS ? mGuildBankTabPrice[Index] : 0; }
722 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
723 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
725 if(condition_id >= mConditions.size())
726 return false;
728 return mConditions[condition_id].Meets(player);
731 GameTele const* GetGameTele(uint32 id) const
733 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
734 if(itr==m_GameTeleMap.end()) return NULL;
735 return &itr->second;
737 GameTele const* GetGameTele(const std::string& name) const;
738 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
739 bool AddGameTele(GameTele& data);
740 bool DeleteGameTele(const std::string& name);
742 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
744 uint32 GetNpcGossip(uint32 entry) const
746 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
747 if(iter == m_mCacheNpcTextIdMap.end())
748 return 0;
750 return iter->second;
753 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
755 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
756 if(iter == m_mCacheTrainerSpellMap.end())
757 return NULL;
759 return &iter->second;
762 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
764 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
765 if(iter == m_mCacheVendorItemMap.end())
766 return NULL;
768 return &iter->second;
770 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
771 bool RemoveVendorItem(uint32 entry,uint32 item);
772 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
774 void LoadScriptNames();
775 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
776 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
777 uint32 GetScriptId(const char *name);
779 int GetOrNewIndexForLocale(LocaleConstant loc);
780 protected:
782 // first free id for selected id type
783 uint32 m_auctionid;
784 uint32 m_mailid;
785 uint32 m_ItemTextId;
786 uint32 m_arenaTeamId;
787 uint32 m_guildId;
788 uint32 m_hiPetNumber;
790 // first free low guid for seelcted guid type
791 uint32 m_hiCharGuid;
792 uint32 m_hiCreatureGuid;
793 uint32 m_hiPetGuid;
794 uint32 m_hiVehicleGuid;
795 uint32 m_hiItemGuid;
796 uint32 m_hiGoGuid;
797 uint32 m_hiDoGuid;
798 uint32 m_hiCorpseGuid;
800 QuestMap mQuestTemplates;
802 typedef UNORDERED_MAP<uint32, GossipText*> GossipTextMap;
803 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
804 typedef UNORDERED_MAP<uint32, uint32> BattleMastersMap;
805 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
806 typedef std::set<uint32> TavernAreaTriggerSet;
807 typedef std::set<uint32> GameObjectForQuestSet;
809 GroupSet mGroupSet;
810 GuildSet mGuildSet;
811 ArenaTeamMap mArenaTeamMap;
813 ItemMap mItems;
814 ItemMap mAitems;
816 ItemTextMap mItemTexts;
818 AuctionHouseObject mHordeAuctions;
819 AuctionHouseObject mAllianceAuctions;
820 AuctionHouseObject mNeutralAuctions;
822 QuestAreaTriggerMap mQuestAreaTriggerMap;
823 BattleMastersMap mBattleMastersMap;
824 TavernAreaTriggerSet mTavernAreaTriggerSet;
825 GameObjectForQuestSet mGameObjectForQuestSet;
826 GossipTextMap mGossipText;
827 AreaTriggerMap mAreaTriggers;
828 AreaTriggerScriptMap mAreaTriggerScripts;
830 RepOnKillMap mRepOnKill;
832 WeatherZoneMap mWeatherZoneMap;
834 PetCreateSpellMap mPetCreateSpell;
836 //character reserved names
837 typedef std::set<std::string> ReservedNamesMap;
838 ReservedNamesMap m_ReservedNames;
840 GraveYardMap mGraveYardMap;
842 GameTeleMap m_GameTeleMap;
844 ScriptNameMap m_scriptNames;
846 typedef std::vector<LocaleConstant> LocalForIndex;
847 LocalForIndex m_LocalForIndex;
849 int DBCLocaleIndex;
851 private:
852 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
853 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
854 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
855 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
857 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
858 // PetLevelInfoMap[creature_id][level]
859 PetLevelInfoMap petInfo; // [creature_id][level]
861 PlayerClassInfo playerClassInfo[MAX_CLASSES];
863 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
864 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
866 typedef std::vector<uint32> PlayerXPperLevel; // [level]
867 PlayerXPperLevel mPlayerXPperLevel;
869 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
870 BaseXPMap mBaseXPTable;
872 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
873 FishingBaseSkillMap mFishingBaseForArea;
875 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
876 HalfNameMap PetHalfName0;
877 HalfNameMap PetHalfName1;
879 MapObjectGuids mMapObjectGuids;
880 CreatureDataMap mCreatureDataMap;
881 CreatureLocaleMap mCreatureLocaleMap;
882 GameObjectDataMap mGameObjectDataMap;
883 GameObjectLocaleMap mGameObjectLocaleMap;
884 ItemLocaleMap mItemLocaleMap;
885 QuestLocaleMap mQuestLocaleMap;
886 NpcTextLocaleMap mNpcTextLocaleMap;
887 PageTextLocaleMap mPageTextLocaleMap;
888 MangosStringLocaleMap mMangosStringLocaleMap;
889 NpcOptionLocaleMap mNpcOptionLocaleMap;
890 RespawnTimes mCreatureRespawnTimes;
891 RespawnTimes mGORespawnTimes;
893 typedef std::vector<uint32> GuildBankTabPriceMap;
894 GuildBankTabPriceMap mGuildBankTabPrice;
896 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
897 typedef std::vector<PlayerCondition> ConditionStore;
898 ConditionStore mConditions;
900 CacheNpcOptionList m_mCacheNpcOptionList;
901 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
902 CacheVendorItemMap m_mCacheVendorItemMap;
903 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
906 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
908 // scripting access functions
909 MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
910 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
911 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
912 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
914 #endif