[7260] Fixed access to uninitilized fields in FleeingMovementGenerator and Creature...
[getmangos.git] / src / game / ObjectMgr.h
blob319ce825ce71be81dc0f478a15d83a55abdc59d7
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( AuctionLocation 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( AuctionLocation location, uint32 highBid );
384 static uint32 GetAuctionDeposit(AuctionLocation 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, uint32 team );
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 void AddGossipText(GossipText *pGText);
443 GossipText *GetGossipText(uint32 Text_ID);
445 WorldSafeLocsEntry const *GetClosestGraveYard(float x, float y, float z, uint32 MapId, uint32 team);
446 bool AddGraveYardLink(uint32 id, uint32 zone, uint32 team, bool inDB = true);
447 void LoadGraveyardZones();
448 GraveYardData const* FindGraveYardData(uint32 id, uint32 zone);
450 AreaTrigger const* GetAreaTrigger(uint32 trigger) const
452 AreaTriggerMap::const_iterator itr = mAreaTriggers.find( trigger );
453 if( itr != mAreaTriggers.end( ) )
454 return &itr->second;
455 return NULL;
458 AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
459 AreaTrigger const* GetMapEntranceTrigger(uint32 Map) const;
461 uint32 GetAreaTriggerScriptId(uint32 trigger_id);
463 ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
465 RepOnKillMap::const_iterator itr = mRepOnKill.find(id);
466 if(itr != mRepOnKill.end())
467 return &itr->second;
468 return NULL;
471 PetCreateSpellEntry const* GetPetCreateSpellEntry(uint32 id) const
473 PetCreateSpellMap::const_iterator itr = mPetCreateSpell.find(id);
474 if(itr != mPetCreateSpell.end())
475 return &itr->second;
476 return NULL;
479 void LoadGuilds();
480 void LoadArenaTeams();
481 void LoadGroups();
482 void LoadQuests();
483 void LoadQuestRelations()
485 LoadGameobjectQuestRelations();
486 LoadGameobjectInvolvedRelations();
487 LoadCreatureQuestRelations();
488 LoadCreatureInvolvedRelations();
490 void LoadGameobjectQuestRelations();
491 void LoadGameobjectInvolvedRelations();
492 void LoadCreatureQuestRelations();
493 void LoadCreatureInvolvedRelations();
495 QuestRelations mGOQuestRelations;
496 QuestRelations mGOQuestInvolvedRelations;
497 QuestRelations mCreatureQuestRelations;
498 QuestRelations mCreatureQuestInvolvedRelations;
500 void LoadGameObjectScripts();
501 void LoadQuestEndScripts();
502 void LoadQuestStartScripts();
503 void LoadEventScripts();
504 void LoadSpellScripts();
506 bool LoadMangosStrings(DatabaseType& db, char const* table, int32 min_value, int32 max_value);
507 bool LoadMangosStrings() { return LoadMangosStrings(WorldDatabase,"mangos_string",MIN_MANGOS_STRING_ID,MAX_MANGOS_STRING_ID); }
508 void LoadDbScriptStrings();
509 void LoadPetCreateSpells();
510 void LoadCreatureLocales();
511 void LoadCreatureTemplates();
512 void LoadCreatures();
513 void LoadCreatureRespawnTimes();
514 void LoadCreatureAddons();
515 void LoadCreatureModelInfo();
516 void LoadEquipmentTemplates();
517 void LoadGameObjectLocales();
518 void LoadGameobjects();
519 void LoadGameobjectRespawnTimes();
520 void LoadItemPrototypes();
521 void LoadItemLocales();
522 void LoadQuestLocales();
523 void LoadNpcTextLocales();
524 void LoadPageTextLocales();
525 void LoadNpcOptionLocales();
526 void LoadInstanceTemplate();
528 void LoadGossipText();
530 void LoadAreaTriggerTeleports();
531 void LoadQuestAreaTriggers();
532 void LoadAreaTriggerScripts();
533 void LoadTavernAreaTriggers();
534 void LoadGameObjectForQuests();
536 void LoadItemTexts();
537 void LoadPageTexts();
539 //load first auction items, because of check if item exists, when loading
540 void LoadAuctionItems();
541 void LoadAuctions();
542 void LoadPlayerInfo();
543 void LoadPetLevelInfo();
544 void LoadExplorationBaseXP();
545 void LoadPetNames();
546 void LoadPetNumber();
547 void LoadCorpses();
548 void LoadFishingBaseSkillLevel();
550 void LoadReputationOnKill();
552 void LoadWeatherZoneChances();
553 void LoadGameTele();
555 void LoadNpcOptions();
556 void LoadNpcTextId();
557 void LoadVendors();
558 void LoadTrainerSpell();
560 std::string GeneratePetName(uint32 entry);
561 uint32 GetBaseXP(uint32 level);
562 uint32 GetXPForLevel(uint32 level);
564 int32 GetFishingBaseSkillLevel(uint32 entry) const
566 FishingBaseSkillMap::const_iterator itr = mFishingBaseForArea.find(entry);
567 return itr != mFishingBaseForArea.end() ? itr->second : 0;
570 void ReturnOrDeleteOldMails(bool serverUp);
572 void SetHighestGuids();
573 uint32 GenerateLowGuid(HighGuid guidhigh);
574 uint32 GenerateAuctionID();
575 uint32 GenerateMailID();
576 uint32 GenerateItemTextID();
577 uint32 GeneratePetNumber();
578 uint32 GenerateArenaTeamId();
579 uint32 GenerateGuildId();
581 uint32 CreateItemText(std::string text);
582 std::string GetItemText( uint32 id )
584 ItemTextMap::const_iterator itr = mItemTexts.find( id );
585 if ( itr != mItemTexts.end() )
586 return itr->second;
587 else
588 return "There is no info for this item";
591 typedef std::multimap<int32, uint32> ExclusiveQuestGroups;
592 ExclusiveQuestGroups mExclusiveQuestGroups;
594 WeatherZoneChances const* GetWeatherChances(uint32 zone_id) const
596 WeatherZoneMap::const_iterator itr = mWeatherZoneMap.find(zone_id);
597 if(itr != mWeatherZoneMap.end())
598 return &itr->second;
599 else
600 return NULL;
603 CellObjectGuids const& GetCellObjectGuids(uint16 mapid, uint8 spawnMode, uint32 cell_id)
605 return mMapObjectGuids[MAKE_PAIR32(mapid,spawnMode)][cell_id];
608 CreatureData const* GetCreatureData(uint32 guid) const
610 CreatureDataMap::const_iterator itr = mCreatureDataMap.find(guid);
611 if(itr==mCreatureDataMap.end()) return NULL;
612 return &itr->second;
614 CreatureData& NewOrExistCreatureData(uint32 guid) { return mCreatureDataMap[guid]; }
615 void DeleteCreatureData(uint32 guid);
616 CreatureLocale const* GetCreatureLocale(uint32 entry) const
618 CreatureLocaleMap::const_iterator itr = mCreatureLocaleMap.find(entry);
619 if(itr==mCreatureLocaleMap.end()) return NULL;
620 return &itr->second;
622 GameObjectLocale const* GetGameObjectLocale(uint32 entry) const
624 GameObjectLocaleMap::const_iterator itr = mGameObjectLocaleMap.find(entry);
625 if(itr==mGameObjectLocaleMap.end()) return NULL;
626 return &itr->second;
628 ItemLocale const* GetItemLocale(uint32 entry) const
630 ItemLocaleMap::const_iterator itr = mItemLocaleMap.find(entry);
631 if(itr==mItemLocaleMap.end()) return NULL;
632 return &itr->second;
634 QuestLocale const* GetQuestLocale(uint32 entry) const
636 QuestLocaleMap::const_iterator itr = mQuestLocaleMap.find(entry);
637 if(itr==mQuestLocaleMap.end()) return NULL;
638 return &itr->second;
640 NpcTextLocale const* GetNpcTextLocale(uint32 entry) const
642 NpcTextLocaleMap::const_iterator itr = mNpcTextLocaleMap.find(entry);
643 if(itr==mNpcTextLocaleMap.end()) return NULL;
644 return &itr->second;
646 PageTextLocale const* GetPageTextLocale(uint32 entry) const
648 PageTextLocaleMap::const_iterator itr = mPageTextLocaleMap.find(entry);
649 if(itr==mPageTextLocaleMap.end()) return NULL;
650 return &itr->second;
652 NpcOptionLocale const* GetNpcOptionLocale(uint32 entry) const
654 NpcOptionLocaleMap::const_iterator itr = mNpcOptionLocaleMap.find(entry);
655 if(itr==mNpcOptionLocaleMap.end()) return NULL;
656 return &itr->second;
659 GameObjectData const* GetGOData(uint32 guid) const
661 GameObjectDataMap::const_iterator itr = mGameObjectDataMap.find(guid);
662 if(itr==mGameObjectDataMap.end()) return NULL;
663 return &itr->second;
665 GameObjectData& NewGOData(uint32 guid) { return mGameObjectDataMap[guid]; }
666 void DeleteGOData(uint32 guid);
668 MangosStringLocale const* GetMangosStringLocale(int32 entry) const
670 MangosStringLocaleMap::const_iterator itr = mMangosStringLocaleMap.find(entry);
671 if(itr==mMangosStringLocaleMap.end()) return NULL;
672 return &itr->second;
674 const char *GetMangosString(int32 entry, int locale_idx) const;
675 const char *GetMangosStringForDBCLocale(int32 entry) const { return GetMangosString(entry,DBCLocaleIndex); }
676 int32 GetDBCLocaleIndex() const { return DBCLocaleIndex; }
677 void SetDBCLocaleIndex(uint32 lang) { DBCLocaleIndex = GetIndexForLocale(LocaleConstant(lang)); }
679 void AddCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid, uint32 instance);
680 void DeleteCorpseCellData(uint32 mapid, uint32 cellid, uint32 player_guid);
682 time_t GetCreatureRespawnTime(uint32 loguid, uint32 instance) { return mCreatureRespawnTimes[MAKE_PAIR64(loguid,instance)]; }
683 void SaveCreatureRespawnTime(uint32 loguid, uint32 instance, time_t t);
684 time_t GetGORespawnTime(uint32 loguid, uint32 instance) { return mGORespawnTimes[MAKE_PAIR64(loguid,instance)]; }
685 void SaveGORespawnTime(uint32 loguid, uint32 instance, time_t t);
686 void DeleteRespawnTimeForInstance(uint32 instance);
688 // grid objects
689 void AddCreatureToGrid(uint32 guid, CreatureData const* data);
690 void RemoveCreatureFromGrid(uint32 guid, CreatureData const* data);
691 void AddGameobjectToGrid(uint32 guid, GameObjectData const* data);
692 void RemoveGameobjectFromGrid(uint32 guid, GameObjectData const* data);
694 // reserved names
695 void LoadReservedPlayersNames();
696 bool IsReservedName(const std::string& name) const;
698 // name with valid structure and symbols
699 static bool IsValidName( const std::string& name, bool create = false );
700 static bool IsValidCharterName( const std::string& name );
701 static bool IsValidPetName( const std::string& name );
703 static bool CheckDeclinedNames(std::wstring mainpart, DeclinedName const& names);
705 int GetIndexForLocale(LocaleConstant loc);
706 LocaleConstant GetLocaleForIndex(int i);
707 // guild bank tabs
708 uint32 GetGuildBankTabPrice(uint8 Index) const { return Index < GUILD_BANK_MAX_TABS ? mGuildBankTabPrice[Index] : 0; }
710 uint16 GetConditionId(ConditionType condition, uint32 value1, uint32 value2);
711 bool IsPlayerMeetToCondition(Player const* player, uint16 condition_id) const
713 if(condition_id >= mConditions.size())
714 return false;
716 return mConditions[condition_id].Meets(player);
719 GameTele const* GetGameTele(uint32 id) const
721 GameTeleMap::const_iterator itr = m_GameTeleMap.find(id);
722 if(itr==m_GameTeleMap.end()) return NULL;
723 return &itr->second;
725 GameTele const* GetGameTele(const std::string& name) const;
726 GameTeleMap const& GetGameTeleMap() const { return m_GameTeleMap; }
727 bool AddGameTele(GameTele& data);
728 bool DeleteGameTele(const std::string& name);
730 CacheNpcOptionList const& GetNpcOptions() const { return m_mCacheNpcOptionList; }
732 uint32 GetNpcGossip(uint32 entry) const
734 CacheNpcTextIdMap::const_iterator iter = m_mCacheNpcTextIdMap.find(entry);
735 if(iter == m_mCacheNpcTextIdMap.end())
736 return 0;
738 return iter->second;
741 TrainerSpellData const* GetNpcTrainerSpells(uint32 entry) const
743 CacheTrainerSpellMap::const_iterator iter = m_mCacheTrainerSpellMap.find(entry);
744 if(iter == m_mCacheTrainerSpellMap.end())
745 return NULL;
747 return &iter->second;
750 VendorItemData const* GetNpcVendorItemList(uint32 entry) const
752 CacheVendorItemMap::const_iterator iter = m_mCacheVendorItemMap.find(entry);
753 if(iter == m_mCacheVendorItemMap.end())
754 return NULL;
756 return &iter->second;
758 void AddVendorItem(uint32 entry,uint32 item, uint32 maxcount, uint32 incrtime, uint32 ExtendedCost);
759 bool RemoveVendorItem(uint32 entry,uint32 item);
760 bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
762 void LoadScriptNames();
763 ScriptNameMap &GetScriptNames() { return m_scriptNames; }
764 const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
765 uint32 GetScriptId(const char *name);
767 int GetOrNewIndexForLocale(LocaleConstant loc);
768 protected:
770 // first free id for selected id type
771 uint32 m_auctionid;
772 uint32 m_mailid;
773 uint32 m_ItemTextId;
774 uint32 m_arenaTeamId;
775 uint32 m_guildId;
776 uint32 m_hiPetNumber;
778 // first free low guid for seelcted guid type
779 uint32 m_hiCharGuid;
780 uint32 m_hiCreatureGuid;
781 uint32 m_hiPetGuid;
782 uint32 m_hiVehicleGuid;
783 uint32 m_hiItemGuid;
784 uint32 m_hiGoGuid;
785 uint32 m_hiDoGuid;
786 uint32 m_hiCorpseGuid;
788 QuestMap mQuestTemplates;
790 typedef UNORDERED_MAP<uint32, GossipText*> GossipTextMap;
791 typedef UNORDERED_MAP<uint32, uint32> QuestAreaTriggerMap;
792 typedef UNORDERED_MAP<uint32, std::string> ItemTextMap;
793 typedef std::set<uint32> TavernAreaTriggerSet;
794 typedef std::set<uint32> GameObjectForQuestSet;
796 GroupSet mGroupSet;
797 GuildSet mGuildSet;
798 ArenaTeamMap mArenaTeamMap;
800 ItemMap mItems;
801 ItemMap mAitems;
803 ItemTextMap mItemTexts;
805 AuctionHouseObject mHordeAuctions;
806 AuctionHouseObject mAllianceAuctions;
807 AuctionHouseObject mNeutralAuctions;
809 QuestAreaTriggerMap mQuestAreaTriggerMap;
810 TavernAreaTriggerSet mTavernAreaTriggerSet;
811 GameObjectForQuestSet mGameObjectForQuestSet;
812 GossipTextMap mGossipText;
813 AreaTriggerMap mAreaTriggers;
814 AreaTriggerScriptMap mAreaTriggerScripts;
816 RepOnKillMap mRepOnKill;
818 WeatherZoneMap mWeatherZoneMap;
820 PetCreateSpellMap mPetCreateSpell;
822 //character reserved names
823 typedef std::set<std::wstring> ReservedNamesMap;
824 ReservedNamesMap m_ReservedNames;
826 GraveYardMap mGraveYardMap;
828 GameTeleMap m_GameTeleMap;
830 ScriptNameMap m_scriptNames;
832 typedef std::vector<LocaleConstant> LocalForIndex;
833 LocalForIndex m_LocalForIndex;
835 int DBCLocaleIndex;
837 private:
838 void LoadScripts(ScriptMapMap& scripts, char const* tablename);
839 void CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids);
840 void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr);
841 void LoadQuestRelationsHelper(QuestRelations& map,char const* table);
843 typedef std::map<uint32,PetLevelInfo*> PetLevelInfoMap;
844 // PetLevelInfoMap[creature_id][level]
845 PetLevelInfoMap petInfo; // [creature_id][level]
847 PlayerClassInfo playerClassInfo[MAX_CLASSES];
849 void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const;
850 PlayerInfo playerInfo[MAX_RACES][MAX_CLASSES];
852 typedef std::vector<uint32> PlayerXPperLevel; // [level]
853 PlayerXPperLevel mPlayerXPperLevel;
855 typedef std::map<uint32,uint32> BaseXPMap; // [area level][base xp]
856 BaseXPMap mBaseXPTable;
858 typedef std::map<uint32,int32> FishingBaseSkillMap; // [areaId][base skill level]
859 FishingBaseSkillMap mFishingBaseForArea;
861 typedef std::map<uint32,std::vector<std::string> > HalfNameMap;
862 HalfNameMap PetHalfName0;
863 HalfNameMap PetHalfName1;
865 MapObjectGuids mMapObjectGuids;
866 CreatureDataMap mCreatureDataMap;
867 CreatureLocaleMap mCreatureLocaleMap;
868 GameObjectDataMap mGameObjectDataMap;
869 GameObjectLocaleMap mGameObjectLocaleMap;
870 ItemLocaleMap mItemLocaleMap;
871 QuestLocaleMap mQuestLocaleMap;
872 NpcTextLocaleMap mNpcTextLocaleMap;
873 PageTextLocaleMap mPageTextLocaleMap;
874 MangosStringLocaleMap mMangosStringLocaleMap;
875 NpcOptionLocaleMap mNpcOptionLocaleMap;
876 RespawnTimes mCreatureRespawnTimes;
877 RespawnTimes mGORespawnTimes;
879 typedef std::vector<uint32> GuildBankTabPriceMap;
880 GuildBankTabPriceMap mGuildBankTabPrice;
882 // Storage for Conditions. First element (index 0) is reserved for zero-condition (nothing required)
883 typedef std::vector<PlayerCondition> ConditionStore;
884 ConditionStore mConditions;
886 CacheNpcOptionList m_mCacheNpcOptionList;
887 CacheNpcTextIdMap m_mCacheNpcTextIdMap;
888 CacheVendorItemMap m_mCacheVendorItemMap;
889 CacheTrainerSpellMap m_mCacheTrainerSpellMap;
892 #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
894 // scripting access functions
895 MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
896 MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
897 MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
898 MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
900 #endif