[6922] Whitespace and newline fixes
[getmangos.git] / src / game / ObjectMgr.h
blob48371b9085cd37e85dd7d7d28e68330e683fbf0b
1 /*
2 * Copyright (C) 2005-2008 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;
468 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
470 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
472 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
473 if(itr != mRepOnKill.end())
474 return &itr->second;
475 return NULL;
478 PetCreateSpellEntry const* GetPetCreateSpellEntry(uint32 id) const
480 PetCreateSpellMap::const_iterator itr = mPetCreateSpell.find(id);
481 if(itr != mPetCreateSpell.end())
482 return &itr->second;
483 return NULL;
486 void LoadGuilds();
487 void LoadArenaTeams();
488 void LoadGroups();
489 void LoadQuests();
490 void LoadQuestRelations()
492 LoadGameobjectQuestRelations();
493 LoadGameobjectInvolvedRelations();
494 LoadCreatureQuestRelations();
495 LoadCreatureInvolvedRelations();
497 void LoadGameobjectQuestRelations();
498 void LoadGameobjectInvolvedRelations();
499 void LoadCreatureQuestRelations();
500 void LoadCreatureInvolvedRelations();
502 QuestRelations mGOQuestRelations;
503 QuestRelations mGOQuestInvolvedRelations;
504 QuestRelations mCreatureQuestRelations;
505 QuestRelations mCreatureQuestInvolvedRelations;
507 void LoadGameObjectScripts();
508 void LoadQuestEndScripts();
509 void LoadQuestStartScripts();
510 void LoadEventScripts();
511 void LoadSpellScripts();
513 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
514 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
515 void LoadDbScriptStrings();
516 void LoadPetCreateSpells();
517 void LoadCreatureLocales();
518 void LoadCreatureTemplates();
519 void LoadCreatures();
520 void LoadCreatureRespawnTimes();
521 void LoadCreatureAddons();
522 void LoadCreatureModelInfo();
523 void LoadEquipmentTemplates();
524 void LoadGameObjectLocales();
525 void LoadGameobjects();
526 void LoadGameobjectRespawnTimes();
527 void LoadItemPrototypes();
528 void LoadItemLocales();
529 void LoadQuestLocales();
530 void LoadNpcTextLocales();
531 void LoadPageTextLocales();
532 void LoadNpcOptionLocales();
533 void LoadInstanceTemplate();
535 void LoadGossipText();
537 void LoadAreaTriggerTeleports();
538 void LoadQuestAreaTriggers();
539 void LoadAreaTriggerScripts();
540 void LoadTavernAreaTriggers();
541 void LoadBattleMastersEntry();
542 void LoadGameObjectForQuests();
544 void LoadItemTexts();
545 void LoadPageTexts();
547 //load first auction items, because of check if item exists, when loading
548 void LoadAuctionItems();
549 void LoadAuctions();
550 void LoadPlayerInfo();
551 void LoadPetLevelInfo();
552 void LoadExplorationBaseXP();
553 void LoadPetNames();
554 void LoadPetNumber();
555 void LoadCorpses();
556 void LoadFishingBaseSkillLevel();
558 void LoadReputationOnKill();
560 void LoadWeatherZoneChances();
561 void LoadGameTele();
563 void LoadNpcOptions();
564 void LoadNpcTextId();
565 void LoadVendors();
566 void LoadTrainerSpell();
568 std::string GeneratePetName(uint32 entry);
569 uint32 GetBaseXP(uint32 level);
571 int32 GetFishingBaseSkillLevel(uint32 entry) const
573 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
574 return itr != mFishingBaseForArea.end() ? itr->second : 0;
577 void ReturnOrDeleteOldMails(bool serverUp);
579 void SetHighestGuids();
580 uint32 GenerateLowGuid(HighGuid guidhigh);
581 uint32 GenerateAuctionID();
582 uint32 GenerateMailID();
583 uint32 GenerateItemTextID();
584 uint32 GeneratePetNumber();
585 uint32 GenerateArenaTeamId();
586 uint32 GenerateGuildId();
588 uint32 CreateItemText(std::string text);
589 std::string GetItemText( uint32 id )
591 ItemTextMap::const_iterator itr = mItemTexts.find( id );
592 if ( itr != mItemTexts.end() )
593 return itr->second;
594 else
595 return "There is no info for this item";
598 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
599 ExclusiveQuestGroups mExclusiveQuestGroups;
601 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
603 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
604 if(itr != mWeatherZoneMap.end())
605 return &itr->second;
606 else
607 return NULL;
610 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
612 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
615 CreatureData const* GetCreatureData(uint32 guid) const
617 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
618 if(itr==mCreatureDataMap.end()) return NULL;
619 return &itr->second;
621 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
622 void DeleteCreatureData(uint32 guid);
623 CreatureLocale const* GetCreatureLocale(uint32 entry) const
625 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
626 if(itr==mCreatureLocaleMap.end()) return NULL;
627 return &itr->second;
629 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
631 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
632 if(itr==mGameObjectLocaleMap.end()) return NULL;
633 return &itr->second;
635 ItemLocale const* GetItemLocale(uint32 entry) const
637 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
638 if(itr==mItemLocaleMap.end()) return NULL;
639 return &itr->second;
641 QuestLocale const* GetQuestLocale(uint32 entry) const
643 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
644 if(itr==mQuestLocaleMap.end()) return NULL;
645 return &itr->second;
647 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
649 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
650 if(itr==mNpcTextLocaleMap.end()) return NULL;
651 return &itr->second;
653 PageTextLocale const* GetPageTextLocale(uint32 entry) const
655 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
656 if(itr==mPageTextLocaleMap.end()) return NULL;
657 return &itr->second;
659 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
661 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
662 if(itr==mNpcOptionLocaleMap.end()) return NULL;
663 return &itr->second;
666 GameObjectData const* GetGOData(uint32 guid) const
668 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
669 if(itr==mGameObjectDataMap.end()) return NULL;
670 return &itr->second;
672 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
673 void DeleteGOData(uint32 guid);
675 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
677 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
678 if(itr==mMangosStringLocaleMap.end()) return NULL;
679 return &itr->second;
681 const char *GetMangosString(int32 entry, int locale_idx) const;
682 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
683 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
684 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
686 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
687 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
689 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
690 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
691 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
692 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
693 void DeleteRespawnTimeForInstance(uint32 instance);
695 // grid objects
696 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
697 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
698 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
699 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
701 // reserved names
702 void LoadReservedPlayersNames();
703 bool IsReservedName(const std::string& name) const
705 return m_ReservedNames.find(name) != m_ReservedNames.end();
708 // name with valid structure and symbols
709 static bool IsValidName( const std::string& name, bool create = false );
710 static bool IsValidCharterName( const std::string& name );
711 static bool IsValidPetName( const std::string& name );
713 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
715 int GetIndexForLocale(LocaleConstant loc);
716 LocaleConstant GetLocaleForIndex(int i);
717 // guild bank tabs
718 uint32 GetGuildBankTabPrice(uint8 Index) const { return Index < GUILD_BANK_MAX_TABS ? mGuildBankTabPrice[Index] : 0; }
720 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
721 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
723 if(condition_id >= mConditions.size())
724 return false;
726 return mConditions[condition_id].Meets(player);
729 GameTele const* GetGameTele(uint32 id) const
731 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
732 if(itr==m_GameTeleMap.end()) return NULL;
733 return &itr->second;
735 GameTele const* GetGameTele(const std::string& name) const;
736 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
737 bool AddGameTele(GameTele& data);
738 bool DeleteGameTele(const std::string& name);
740 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
742 uint32 GetNpcGossip(uint32 entry) const
744 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
745 if(iter == m_mCacheNpcTextIdMap.end())
746 return 0;
748 return iter->second;
751 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
753 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
754 if(iter == m_mCacheTrainerSpellMap.end())
755 return NULL;
757 return &iter->second;
760 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
762 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
763 if(iter == m_mCacheVendorItemMap.end())
764 return NULL;
766 return &iter->second;
768 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
769 bool RemoveVendorItem(uint32 entry,uint32 item);
770 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
772 void LoadScriptNames();
773 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
774 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
775 uint32 GetScriptId(const char *name);
776 protected:
778 // first free id for selected id type
779 uint32 m_auctionid;
780 uint32 m_mailid;
781 uint32 m_ItemTextId;
782 uint32 m_arenaTeamId;
783 uint32 m_guildId;
784 uint32 m_hiPetNumber;
786 // first free low guid for seelcted guid type
787 uint32 m_hiCharGuid;
788 uint32 m_hiCreatureGuid;
789 uint32 m_hiPetGuid;
790 uint32 m_hiItemGuid;
791 uint32 m_hiGoGuid;
792 uint32 m_hiDoGuid;
793 uint32 m_hiCorpseGuid;
795 QuestMap mQuestTemplates;
797 typedef UNORDERED_MAP<uint32, GossipText*> GossipTextMap;
798 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
799 typedef UNORDERED_MAP<uint32, uint32> BattleMastersMap;
800 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
801 typedef std::set<uint32> TavernAreaTriggerSet;
802 typedef std::set<uint32> GameObjectForQuestSet;
804 GroupSet mGroupSet;
805 GuildSet mGuildSet;
806 ArenaTeamMap mArenaTeamMap;
808 ItemMap mItems;
809 ItemMap mAitems;
811 ItemTextMap mItemTexts;
813 AuctionHouseObject mHordeAuctions;
814 AuctionHouseObject mAllianceAuctions;
815 AuctionHouseObject mNeutralAuctions;
817 QuestAreaTriggerMap mQuestAreaTriggerMap;
818 BattleMastersMap mBattleMastersMap;
819 TavernAreaTriggerSet mTavernAreaTriggerSet;
820 GameObjectForQuestSet mGameObjectForQuestSet;
821 GossipTextMap mGossipText;
822 AreaTriggerMap mAreaTriggers;
823 AreaTriggerScriptMap mAreaTriggerScripts;
825 RepOnKillMap mRepOnKill;
827 WeatherZoneMap mWeatherZoneMap;
829 PetCreateSpellMap mPetCreateSpell;
831 //character reserved names
832 typedef std::set<std::string> ReservedNamesMap;
833 ReservedNamesMap m_ReservedNames;
835 GraveYardMap mGraveYardMap;
837 GameTeleMap m_GameTeleMap;
839 ScriptNameMap m_scriptNames;
841 typedef std::vector<LocaleConstant> LocalForIndex;
842 LocalForIndex m_LocalForIndex;
843 int GetOrNewIndexForLocale(LocaleConstant loc);
845 int DBCLocaleIndex;
847 private:
848 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
849 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
850 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
851 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
853 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
854 // PetLevelInfoMap[creature_id][level]
855 PetLevelInfoMap petInfo; // [creature_id][level]
857 PlayerClassInfo playerClassInfo[MAX_CLASSES];
859 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
860 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
862 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
863 BaseXPMap mBaseXPTable;
865 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
866 FishingBaseSkillMap mFishingBaseForArea;
868 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
869 HalfNameMap PetHalfName0;
870 HalfNameMap PetHalfName1;
872 MapObjectGuids mMapObjectGuids;
873 CreatureDataMap mCreatureDataMap;
874 CreatureLocaleMap mCreatureLocaleMap;
875 GameObjectDataMap mGameObjectDataMap;
876 GameObjectLocaleMap mGameObjectLocaleMap;
877 ItemLocaleMap mItemLocaleMap;
878 QuestLocaleMap mQuestLocaleMap;
879 NpcTextLocaleMap mNpcTextLocaleMap;
880 PageTextLocaleMap mPageTextLocaleMap;
881 MangosStringLocaleMap mMangosStringLocaleMap;
882 NpcOptionLocaleMap mNpcOptionLocaleMap;
883 RespawnTimes mCreatureRespawnTimes;
884 RespawnTimes mGORespawnTimes;
886 typedef std::vector<uint32> GuildBankTabPriceMap;
887 GuildBankTabPriceMap mGuildBankTabPrice;
889 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
890 typedef std::vector<PlayerCondition> ConditionStore;
891 ConditionStore mConditions;
893 CacheNpcOptionList m_mCacheNpcOptionList;
894 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
895 CacheVendorItemMap m_mCacheVendorItemMap;
896 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
899 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
901 // scripting access functions
902 MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
903 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
904 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
905 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
907 #endif