Show
Ignore:
Timestamp:
11/22/08 00:36:22 (17 years ago)
Author:
yumileroy
Message:

Merged commit 269 (5f0e38da128a).

Original author: gvcoman
Date: 2008-11-21 14:34:05-05:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/ObjectMgr.cpp

    r272 r279  
    1111 * This program is distributed in the hope that it will be useful, 
    1212 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414 * GNU General Public License for more details. 
    1515 * 
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
    1919 */ 
    2020 
     
    2222#include "Database/DatabaseEnv.h" 
    2323#include "Database/SQLStorage.h" 
     24#include "Database/SQLStorageImpl.h" 
    2425 
    2526#include "Log.h" 
     
    117118    m_hiDoGuid          = 1; 
    118119    m_hiCorpseGuid      = 1; 
    119  
    120120    m_hiPetNumber       = 1; 
     121    m_ItemTextId        = 1; 
     122    m_mailid            = 1; 
     123    m_auctionid         = 1; 
     124    m_guildId           = 1; 
     125    m_arenaTeamId       = 1; 
    121126 
    122127    mGuildBankTabPrice.resize(GUILD_BANK_MAX_TABS); 
     
    416421 
    417422        //prepare mail data... : 
    418         uint32 itemTextId = this->CreateItemText( msgAuctionWonBody.str() ); 
     423        uint32 itemTextId = CreateItemText( msgAuctionWonBody.str() ); 
    419424 
    420425        // set owner to bidder (to prevent delete item with sender char deleting) 
     
    467472        sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str()); 
    468473 
    469         uint32 itemTextId = this->CreateItemText( msgAuctionSalePendingBody.str() ); 
     474        uint32 itemTextId = CreateItemText( msgAuctionSalePendingBody.str() ); 
    470475 
    471476        WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION); 
     
    499504        sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str()); 
    500505 
    501         uint32 itemTextId = this->CreateItemText( auctionSuccessfulBody.str() ); 
     506        uint32 itemTextId = CreateItemText( auctionSuccessfulBody.str() ); 
    502507 
    503508        uint32 profit = auction->bid + auction->deposit - auctionCut; 
     
    546551        // will delete item or place to receiver mail list 
    547552        WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->location, GUID_LOPART(owner_guid), subject.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE); 
    548  
    549553    } 
    550554    // owner not found 
     
    564568void ObjectMgr::LoadCreatureLocales() 
    565569{ 
    566     mCreatureLocaleMap.clear(); 
    567      
     570    mCreatureLocaleMap.clear();                              // need for reload case 
     571 
    568572    QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,subname_loc1,name_loc2,subname_loc2,name_loc3,subname_loc3,name_loc4,subname_loc4,name_loc5,subname_loc5,name_loc6,subname_loc6,name_loc7,subname_loc7,name_loc8,subname_loc8 FROM locales_creature"); 
    569573 
     
    624628    sLog.outString( ">> Loaded %u creature locale strings", mCreatureLocaleMap.size() ); 
    625629} 
    626  
     630    
    627631void ObjectMgr::LoadNpcOptionLocales() 
    628632{ 
     
    693697} 
    694698 
     699struct SQLCreatureLoader : public SQLStorageLoaderBase<SQLCreatureLoader> 
     700{ 
     701    template<class D> 
     702    void convert_from_str(uint32 field_pos, char *src, D &dst) 
     703    { 
     704        dst = D(objmgr.GetScriptId(src)); 
     705    } 
     706}; 
     707 
    695708void ObjectMgr::LoadCreatureTemplates() 
    696709{ 
    697     sCreatureStorage.Load(); 
     710    SQLCreatureLoader loader; 
     711    loader.Load(sCreatureStorage); 
    698712 
    699713    sLog.outString( ">> Loaded %u creature definitions", sCreatureStorage.RecordCount ); 
     
    15131527        aItem->location = fields[11].GetUInt8(); 
    15141528        //check if sold item exists 
    1515         if ( this->GetAItem( aItem->item_guidlow ) ) 
     1529        if ( GetAItem( aItem->item_guidlow ) ) 
    15161530        { 
    15171531            GetAuctionsMap( aItem->location )->AddAuction(aItem); 
     
    15331547void ObjectMgr::LoadItemLocales() 
    15341548{ 
    1535     mItemLocaleMap.clear(); 
    1536      
     1549    mItemLocaleMap.clear();                                 // need for reload case 
     1550 
    15371551    QueryResult *result = WorldDatabase.Query("SELECT entry,name_loc1,description_loc1,name_loc2,description_loc2,name_loc3,description_loc3,name_loc4,description_loc4,name_loc5,description_loc5,name_loc6,description_loc6,name_loc7,description_loc7,name_loc8,description_loc8 FROM locales_item"); 
    15381552 
     
    15951609} 
    15961610 
     1611struct SQLItemLoader : public SQLStorageLoaderBase<SQLItemLoader> 
     1612{ 
     1613    template<class D> 
     1614    void convert_from_str(uint32 field_pos, char *src, D &dst) 
     1615    { 
     1616        dst = D(objmgr.GetScriptId(src)); 
     1617    } 
     1618}; 
     1619 
    15971620void ObjectMgr::LoadItemPrototypes() 
    15981621{ 
    1599     sItemStorage.Load (); 
     1622    SQLItemLoader loader; 
     1623    loader.Load(sItemStorage); 
    16001624    sLog.outString( ">> Loaded %u item prototypes", sItemStorage.RecordCount ); 
    16011625    sLog.outString(); 
     
    25072531            if (sWorld.getConfig(CONFIG_EXPANSION) < 1 && (race == RACE_BLOODELF || race == RACE_DRAENEI)) 
    25082532                continue; 
    2509                  
     2533 
    25102534            // skip expansion classes if not playing with expansion 
    25112535            if (sWorld.getConfig(CONFIG_EXPANSION) < 2 && class_ == CLASS_DEATH_KNIGHT) 
     
    35563580void ObjectMgr::LoadQuestLocales() 
    35573581{ 
    3558     mQuestLocaleMap.clear(); 
     3582    mQuestLocaleMap.clear();                                // need for reload case 
    35593583 
    35603584    QueryResult *result = WorldDatabase.Query("SELECT entry," 
     
    37503774    scripts.clear();                                        // need for reload support 
    37513775 
    3752     QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,datatext, x, y, z, o FROM %s", tablename ); 
     3776    QueryResult *result = WorldDatabase.PQuery( "SELECT id,delay,command,datalong,datalong2,dataint, x, y, z, o FROM %s", tablename ); 
    37533777 
    37543778    uint32 count = 0; 
     
    37723796        Field *fields = result->Fetch(); 
    37733797        ScriptInfo tmp; 
    3774         tmp.id = fields[0].GetUInt32(); 
    3775         tmp.delay = fields[1].GetUInt32(); 
    3776         tmp.command = fields[2].GetUInt32(); 
    3777         tmp.datalong = fields[3].GetUInt32(); 
     3798        tmp.id        = fields[0].GetUInt32(); 
     3799        tmp.delay     = fields[1].GetUInt32(); 
     3800        tmp.command   = fields[2].GetUInt32(); 
     3801        tmp.datalong  = fields[3].GetUInt32(); 
    37783802        tmp.datalong2 = fields[4].GetUInt32(); 
    3779         tmp.datatext = fields[5].GetCppString(); 
    3780         tmp.x = fields[6].GetFloat(); 
    3781         tmp.y = fields[7].GetFloat(); 
    3782         tmp.z = fields[8].GetFloat(); 
    3783         tmp.o = fields[9].GetFloat(); 
     3803        tmp.dataint   = fields[5].GetInt32(); 
     3804        tmp.x         = fields[6].GetFloat(); 
     3805        tmp.y         = fields[7].GetFloat(); 
     3806        tmp.z         = fields[8].GetFloat(); 
     3807        tmp.o         = fields[9].GetFloat(); 
    37843808 
    37853809        // generic command args check 
     
    37933817                    continue; 
    37943818                } 
     3819                if(tmp.dataint==0) 
     3820                { 
     3821                    sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,tmp.id); 
     3822                    continue; 
     3823                } 
     3824                if(tmp.dataint < MIN_DB_SCRIPT_STRING_ID || tmp.dataint >= MAX_DB_SCRIPT_STRING_ID) 
     3825                { 
     3826                    sLog.outErrorDb("Table `%s` has out of range text id (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.dataint,MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID,tmp.id); 
     3827                    continue; 
     3828                } 
     3829 
     3830                // if(!objmgr.GetMangosStringLocale(tmp.dataint)) will checked after db_script_string loading 
    37953831                break; 
    37963832            } 
     
    41574193void ObjectMgr::LoadPageTextLocales() 
    41584194{ 
    4159     mPageTextLocaleMap.clear(); 
    4160      
     4195    mPageTextLocaleMap.clear();                             // need for reload case 
     4196 
    41614197    QueryResult *result = WorldDatabase.Query("SELECT entry,text_loc1,text_loc2,text_loc3,text_loc4,text_loc5,text_loc6,text_loc7,text_loc8 FROM locales_page_text"); 
    41624198 
     
    42074243} 
    42084244 
     4245struct SQLInstanceLoader : public SQLStorageLoaderBase<SQLInstanceLoader> 
     4246{ 
     4247    template<class D> 
     4248    void convert_from_str(uint32 field_pos, char *src, D &dst) 
     4249    { 
     4250        dst = D(objmgr.GetScriptId(src)); 
     4251    } 
     4252}; 
     4253 
    42094254void ObjectMgr::LoadInstanceTemplate() 
    42104255{ 
    4211     sInstanceTemplate.Load(); 
     4256    SQLInstanceLoader loader; 
     4257    loader.Load(sInstanceTemplate); 
    42124258 
    42134259    for(uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++) 
     
    43254371void ObjectMgr::LoadNpcTextLocales() 
    43264372{ 
    4327     mNpcTextLocaleMap.clear(); 
    4328      
     4373    mNpcTextLocaleMap.clear();                              // need for reload case 
     4374 
    43294375    QueryResult *result = WorldDatabase.Query("SELECT entry," 
    43304376        "Text0_0_loc1,Text0_1_loc1,Text1_0_loc1,Text1_1_loc1,Text2_0_loc1,Text2_1_loc1,Text3_0_loc1,Text3_1_loc1,Text4_0_loc1,Text4_1_loc1,Text5_0_loc1,Text5_1_loc1,Text6_0_loc1,Text6_1_loc1,Text7_0_loc1,Text7_1_loc1," 
     
    46234669 
    46244670        uint32 Trigger_ID      = fields[0].GetUInt32(); 
    4625         std::string scriptName = fields[1].GetCppString(); 
     4671        const char *scriptName = fields[1].GetString(); 
    46264672 
    46274673        AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); 
     
    46314677            continue; 
    46324678        } 
    4633         mAreaTriggerScripts[Trigger_ID] = scriptName; 
     4679        mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName); 
    46344680    } while( result->NextRow() ); 
    46354681 
     
    46394685    sLog.outString( ">> Loaded %u areatrigger scripts", count ); 
    46404686} 
     4687 
    46414688uint32 ObjectMgr::GetNearestTaxiNode( float x, float y, float z, uint32 mapid ) 
    46424689{ 
     
    46974744uint16 ObjectMgr::GetTaxiMount( uint32 id, uint32 team ) 
    46984745{ 
    4699     uint32 mount_entry = 0; 
    4700     uint32 mount_id = 0; 
     4746    uint16 mount_entry = 0; 
     4747    uint16 mount_id = 0; 
    47014748 
    47024749    TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(id); 
    4703     if (node) 
     4750    if(node) 
    47044751    { 
    47054752        if (team == ALLIANCE) mount_entry = node->alliance_mount_type; 
     
    49404987    } 
    49414988 
    4942             // find now nearest graveyard at same map 
    49434989    if(entryNear) 
    49444990        return entryNear; 
     
    51815227    { 
    51825228        m_hiCharGuid = (*result)[0].GetUInt32()+1; 
    5183  
    51845229        delete result; 
    51855230    } 
     
    51895234    { 
    51905235        m_hiCreatureGuid = (*result)[0].GetUInt32()+1; 
    5191  
    51925236        delete result; 
    51935237    } 
    51945238 
    5195     result = CharacterDatabase.Query( "SELECT MAX(id) FROM character_pet" ); 
    5196     if( result ) 
    5197     { 
    5198         m_hiPetGuid = (*result)[0].GetUInt32()+1; 
    5199  
    5200         delete result; 
    5201     } 
     5239    // pet guids are not saved to DB, set to 0 (pet guid != pet id) 
     5240    m_hiPetGuid = 0; 
    52025241 
    52035242    result = CharacterDatabase.Query( "SELECT MAX(guid) FROM item_instance" ); 
     
    52055244    { 
    52065245        m_hiItemGuid = (*result)[0].GetUInt32()+1; 
    5207  
    52085246        delete result; 
    52095247    } 
     
    52195257    { 
    52205258        m_hiGoGuid = (*result)[0].GetUInt32()+1; 
    5221  
    52225259        delete result; 
    52235260    } 
     
    52275264    { 
    52285265        m_auctionid = (*result)[0].GetUInt32()+1; 
    5229  
    52305266        delete result; 
    52315267    } 
    5232     else 
    5233     { 
    5234         m_auctionid = 0; 
    5235     } 
     5268 
    52365269    result = CharacterDatabase.Query( "SELECT MAX(id) FROM mail" ); 
    52375270    if( result ) 
    52385271    { 
    52395272        m_mailid = (*result)[0].GetUInt32()+1; 
    5240  
    52415273        delete result; 
    52425274    } 
    5243     else 
    5244     { 
    5245         m_mailid = 0; 
    5246     } 
     5275 
    52475276    result = CharacterDatabase.Query( "SELECT MAX(id) FROM item_text" ); 
    52485277    if( result ) 
    52495278    { 
    5250         m_ItemTextId = (*result)[0].GetUInt32(); 
    5251  
     5279        m_ItemTextId = (*result)[0].GetUInt32()+1; 
    52525280        delete result; 
    52535281    } 
    5254     else 
    5255         m_ItemTextId = 0; 
    52565282 
    52575283    result = CharacterDatabase.Query( "SELECT MAX(guid) FROM corpse" ); 
     
    52595285    { 
    52605286        m_hiCorpseGuid = (*result)[0].GetUInt32()+1; 
    5261  
    52625287        delete result; 
    52635288    } 
     5289 
     5290    result = CharacterDatabase.Query("SELECT MAX(arenateamid) FROM arena_team"); 
     5291    if (result) 
     5292    { 
     5293        m_arenaTeamId = (*result)[0].GetUInt32()+1; 
     5294        delete result; 
     5295    } 
     5296 
     5297    result = CharacterDatabase.Query( "SELECT MAX(guildid) FROM guild" ); 
     5298    if (result) 
     5299    { 
     5300        m_guildId = (*result)[0].GetUInt32()+1; 
     5301        delete result; 
     5302    } 
     5303} 
     5304 
     5305uint32 ObjectMgr::GenerateArenaTeamId() 
     5306{ 
     5307    if(m_arenaTeamId>=0xFFFFFFFE) 
     5308    { 
     5309        sLog.outError("Arena team ids overflow!! Can't continue, shutting down server. "); 
     5310        World::StopNow(ERROR_EXIT_CODE); 
     5311    } 
     5312    return m_arenaTeamId++; 
     5313} 
     5314 
     5315uint32 ObjectMgr::GenerateGuildId() 
     5316{ 
     5317    if(m_guildId>=0xFFFFFFFE) 
     5318    { 
     5319        sLog.outError("Guild ids overflow!! Can't continue, shutting down server. "); 
     5320        World::StopNow(ERROR_EXIT_CODE); 
     5321    } 
     5322    return m_guildId++; 
    52645323} 
    52655324 
    52665325uint32 ObjectMgr::GenerateAuctionID() 
    52675326{ 
    5268     ++m_auctionid; 
    5269     if(m_auctionid>=0xFFFFFFFF) 
     5327    if(m_auctionid>=0xFFFFFFFE) 
    52705328    { 
    52715329        sLog.outError("Auctions ids overflow!! Can't continue, shutting down server. "); 
    5272         sWorld.m_stopEvent = true; 
    5273     } 
    5274     return m_auctionid; 
     5330        World::StopNow(ERROR_EXIT_CODE); 
     5331    } 
     5332    return m_auctionid++; 
    52755333} 
    52765334 
    52775335uint32 ObjectMgr::GenerateMailID() 
    52785336{ 
    5279     ++m_mailid; 
    5280     if(m_mailid>=0xFFFFFFFF) 
     5337    if(m_mailid>=0xFFFFFFFE) 
    52815338    { 
    52825339        sLog.outError("Mail ids overflow!! Can't continue, shutting down server. "); 
    5283         sWorld.m_stopEvent = true; 
    5284     } 
    5285     return m_mailid; 
     5340        World::StopNow(ERROR_EXIT_CODE); 
     5341    } 
     5342    return m_mailid++; 
    52865343} 
    52875344 
    52885345uint32 ObjectMgr::GenerateItemTextID() 
    52895346{ 
    5290     ++m_ItemTextId; 
    5291     if(m_ItemTextId>=0xFFFFFFFF) 
     5347    if(m_ItemTextId>=0xFFFFFFFE) 
    52925348    { 
    52935349        sLog.outError("Item text ids overflow!! Can't continue, shutting down server. "); 
    5294         sWorld.m_stopEvent = true; 
    5295     } 
    5296     return m_ItemTextId; 
     5350        World::StopNow(ERROR_EXIT_CODE); 
     5351    } 
     5352    return m_ItemTextId++; 
    52975353} 
    52985354 
     
    53165372    { 
    53175373        case HIGHGUID_ITEM: 
    5318             ++m_hiItemGuid; 
    5319             if(m_hiItemGuid>=0xFFFFFFFF) 
     5374            if(m_hiItemGuid>=0xFFFFFFFE) 
    53205375            { 
    53215376                sLog.outError("Item guid overflow!! Can't continue, shutting down server. "); 
    5322                 sWorld.m_stopEvent = true; 
    5323             } 
    5324             return m_hiItemGuid; 
     5377                World::StopNow(ERROR_EXIT_CODE); 
     5378            } 
     5379            return m_hiItemGuid++; 
    53255380        case HIGHGUID_UNIT: 
    5326             ++m_hiCreatureGuid; 
    5327             if(m_hiCreatureGuid>=0x00FFFFFF) 
     5381            if(m_hiCreatureGuid>=0x00FFFFFE) 
    53285382            { 
    53295383                sLog.outError("Creature guid overflow!! Can't continue, shutting down server. "); 
    5330                 sWorld.m_stopEvent = true; 
    5331             } 
    5332             return m_hiCreatureGuid; 
     5384                World::StopNow(ERROR_EXIT_CODE); 
     5385            } 
     5386            return m_hiCreatureGuid++; 
    53335387        case HIGHGUID_PET: 
    5334             ++m_hiPetGuid; 
    5335             if(m_hiPetGuid>=0x00FFFFFF) 
     5388            if(m_hiPetGuid>=0x00FFFFFE) 
    53365389            { 
    53375390                sLog.outError("Pet guid overflow!! Can't continue, shutting down server. "); 
    5338                 sWorld.m_stopEvent = true; 
    5339             } 
    5340             return m_hiPetGuid; 
     5391                World::StopNow(ERROR_EXIT_CODE); 
     5392            } 
     5393            return m_hiPetGuid++; 
    53415394        case HIGHGUID_PLAYER: 
    5342             ++m_hiCharGuid; 
    5343             if(m_hiCharGuid>=0xFFFFFFFF) 
     5395            if(m_hiCharGuid>=0xFFFFFFFE) 
    53445396            { 
    53455397                sLog.outError("Players guid overflow!! Can't continue, shutting down server. "); 
    5346                 sWorld.m_stopEvent = true; 
    5347             } 
    5348             return m_hiCharGuid; 
     5398                World::StopNow(ERROR_EXIT_CODE); 
     5399            } 
     5400            return m_hiCharGuid++; 
    53495401        case HIGHGUID_GAMEOBJECT: 
    5350             ++m_hiGoGuid; 
    5351             if(m_hiGoGuid>=0x00FFFFFF) 
     5402            if(m_hiGoGuid>=0x00FFFFFE) 
    53525403            { 
    53535404                sLog.outError("Gameobject guid overflow!! Can't continue, shutting down server. "); 
    5354                 sWorld.m_stopEvent = true; 
    5355             } 
    5356             return m_hiGoGuid; 
     5405                World::StopNow(ERROR_EXIT_CODE); 
     5406            } 
     5407            return m_hiGoGuid++; 
    53575408        case HIGHGUID_CORPSE: 
    5358             ++m_hiCorpseGuid; 
    5359             if(m_hiCorpseGuid>=0xFFFFFFFF) 
     5409            if(m_hiCorpseGuid>=0xFFFFFFFE) 
    53605410            { 
    53615411                sLog.outError("Corpse guid overflow!! Can't continue, shutting down server. "); 
    5362                 sWorld.m_stopEvent = true; 
    5363             } 
    5364             return m_hiCorpseGuid; 
     5412                World::StopNow(ERROR_EXIT_CODE); 
     5413            } 
     5414            return m_hiCorpseGuid++; 
    53655415        case HIGHGUID_DYNAMICOBJECT: 
    5366             ++m_hiDoGuid; 
    5367             if(m_hiDoGuid>=0xFFFFFFFF) 
     5416            if(m_hiDoGuid>=0xFFFFFFFE) 
    53685417            { 
    53695418                sLog.outError("DynamicObject guid overflow!! Can't continue, shutting down server. "); 
    5370                 sWorld.m_stopEvent = true; 
    5371             } 
    5372             return m_hiDoGuid; 
     5419                World::StopNow(ERROR_EXIT_CODE); 
     5420            } 
     5421            return m_hiDoGuid++; 
    53735422        default: 
    53745423            ASSERT(0); 
     
    53815430void ObjectMgr::LoadGameObjectLocales() 
    53825431{ 
    5383     mGameObjectLocaleMap.clear(); 
    5384      
     5432    mGameObjectLocaleMap.clear();                           // need for reload case 
     5433 
    53855434    QueryResult *result = WorldDatabase.Query("SELECT entry," 
    53865435        "name_loc1,name_loc2,name_loc3,name_loc4,name_loc5,name_loc6,name_loc7,name_loc8," 
     
    54505499} 
    54515500 
     5501struct SQLGameObjectLoader : public SQLStorageLoaderBase<SQLGameObjectLoader> 
     5502{ 
     5503    template<class D> 
     5504    void convert_from_str(uint32 field_pos, char *src, D &dst) 
     5505    { 
     5506        dst = D(objmgr.GetScriptId(src)); 
     5507    } 
     5508}; 
     5509 
    54525510void ObjectMgr::LoadGameobjectInfo() 
    54535511{ 
    5454     sGOStorage.Load(); 
     5512    SQLGameObjectLoader loader; 
     5513    loader.Load(sGOStorage); 
    54555514 
    54565515    // some checks 
     
    66256684} 
    66266685 
    6627 const char* ObjectMgr::GetAreaTriggerScriptName(uint32 id) 
    6628 { 
    6629     AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(id); 
     6686uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id) 
     6687{ 
     6688    AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id); 
    66306689    if(i!= mAreaTriggerScripts.end()) 
    6631         return i->second.c_str(); 
    6632     return ""; 
     6690        return i->second; 
     6691    return 0; 
    66336692} 
    66346693 
     
    66756734            return false; 
    66766735        } 
    6677                 case CONDITION_NO_AURA: 
    6678                         return !player->HasAura(value1, value2); 
    6679                 case CONDITION_ACTIVE_EVENT: 
    6680                         return gameeventmgr.IsActiveEvent(value1); 
     6736        case CONDITION_NO_AURA: 
     6737            return !player->HasAura(value1, value2); 
     6738        case CONDITION_ACTIVE_EVENT: 
     6739            return gameeventmgr.IsActiveEvent(value1); 
    66816740        default: 
    66826741            return false; 
     
    67996858            break; 
    68006859        } 
    6801                 case CONDITION_NO_AURA: 
    6802                 { 
    6803                         if(!sSpellStore.LookupEntry(value1)) 
    6804                         { 
    6805                                 sLog.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1); 
    6806                                 return false; 
    6807                         } 
    6808                         if(value2 > 2) 
    6809                         { 
    6810                                 sLog.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2); 
    6811                                 return false; 
    6812                         } 
    6813                         break; 
    6814                 } 
    6815                 case CONDITION_ACTIVE_EVENT: 
    6816                 { 
    6817                         GameEvent::GameEventDataMap const& events = gameeventmgr.GetEventMap(); 
    6818                         if(value1 >=events.size() || !events[value1].isValid()) 
    6819                         { 
    6820                                 sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1); 
    6821                                 return false; 
    6822                         } 
    6823                         break; 
    6824                 } 
     6860        case CONDITION_NO_AURA: 
     6861        { 
     6862            if(!sSpellStore.LookupEntry(value1)) 
     6863            { 
     6864                sLog.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1); 
     6865                return false; 
     6866            } 
     6867            if(value2 > 2) 
     6868            { 
     6869                sLog.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2); 
     6870                return false; 
     6871            } 
     6872            break; 
     6873        } 
     6874        case CONDITION_ACTIVE_EVENT: 
     6875        { 
     6876            GameEvent::GameEventDataMap const& events = gameeventmgr.GetEventMap(); 
     6877            if(value1 >=events.size() || !events[value1].isValid()) 
     6878            { 
     6879                sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1); 
     6880                return false; 
     6881            } 
     6882            break; 
     6883        } 
    68256884    } 
    68266885    return true; 
     
    69527011        if(itr->first > new_id) 
    69537012            new_id = itr->first; 
    6954      
     7013 
    69557014    // use next 
    69567015    ++new_id; 
     
    69927051void ObjectMgr::LoadTrainerSpell() 
    69937052{ 
    6994     // For reload case  
     7053    // For reload case 
    69957054    for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr) 
    69967055        itr->second.Clear(); 
     
    70837142void ObjectMgr::LoadVendors() 
    70847143{ 
    7085     // For reload case  
     7144    // For reload case 
    70867145    for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr) 
    70877146        itr->second.Clear(); 
     
    71907249        "SELECT id,gossip_id,npcflag,icon,action,box_money,coded,option_text,box_text " 
    71917250        "FROM npc_option"); 
     7251 
    71927252    if( !result ) 
    71937253    { 
     
    73427402} 
    73437403 
     7404void ObjectMgr::LoadScriptNames() 
     7405{ 
     7406    m_scriptNames.push_back(""); 
     7407    QueryResult *result = WorldDatabase.Query( 
     7408      "SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' " 
     7409      "UNION " 
     7410      "SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' " 
     7411      "UNION " 
     7412      "SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' " 
     7413      "UNION " 
     7414      "SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' " 
     7415      "UNION " 
     7416      "SELECT DISTINCT(script) FROM instance_template WHERE script <> ''"); 
     7417    if(result) 
     7418    { 
     7419        do 
     7420        { 
     7421            m_scriptNames.push_back((*result)[0].GetString()); 
     7422        } while (result->NextRow()); 
     7423        delete result; 
     7424    } 
     7425 
     7426    std::sort(m_scriptNames.begin(), m_scriptNames.end()); 
     7427} 
     7428 
     7429uint32 ObjectMgr::GetScriptId(const char *name) 
     7430{ 
     7431    // use binary search to find the script name in the sorted vector 
     7432    // assume "" is the first element 
     7433    if(!name) return 0; 
     7434    ScriptNameMap::const_iterator itr = 
     7435        std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name); 
     7436    if(itr == m_scriptNames.end()) return 0; 
     7437    return itr - m_scriptNames.begin(); 
     7438} 
     7439 
     7440void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids) 
     7441{ 
     7442    for(ScriptMapMap::const_iterator itrMM = scripts.begin(); itrMM != scripts.end(); ++itrMM) 
     7443    { 
     7444        for(ScriptMap::const_iterator itrM = itrMM->second.begin(); itrM != itrMM->second.end(); ++itrM) 
     7445        { 
     7446            if(itrM->second.dataint) 
     7447            { 
     7448                if(!GetTrinityStringLocale (itrM->second.dataint)) 
     7449                    sLog.outErrorDb( "Table `db_script_string` has not existed string id  %u", *itrM); 
     7450 
     7451                if(ids.count(itrM->second.dataint)) 
     7452                    ids.erase(itrM->second.dataint); 
     7453            } 
     7454        } 
     7455    } 
     7456} 
     7457 
     7458void ObjectMgr::LoadDbScriptStrings() 
     7459{ 
     7460    LoadTrinityStrings(WorldDatabase,"db_script_string",MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID); 
     7461 
     7462    std::set<int32> ids; 
     7463 
     7464    for(int32 i = MIN_DB_SCRIPT_STRING_ID; i < MAX_DB_SCRIPT_STRING_ID; ++i) 
     7465        if(GetTrinityStringLocale(i)) 
     7466            ids.insert(i); 
     7467 
     7468    CheckScripts(sQuestEndScripts,ids); 
     7469    CheckScripts(sQuestStartScripts,ids); 
     7470    CheckScripts(sSpellScripts,ids); 
     7471    CheckScripts(sGameObjectScripts,ids); 
     7472    CheckScripts(sEventScripts,ids); 
     7473 
     7474    for(std::set<int32>::const_iterator itr = ids.begin(); itr != ids.end(); ++itr) 
     7475        sLog.outErrorDb( "Table `db_script_string` has unused string id  %u", *itr); 
     7476} 
     7477 
    73447478// Functions for scripting access 
    7345 const char* GetAreaTriggerScriptNameById(uint32 id) 
    7346 { 
    7347     return objmgr.GetAreaTriggerScriptName(id); 
     7479uint32 GetAreaTriggerScriptId(uint32 trigger_id) 
     7480{ 
     7481    return objmgr.GetAreaTriggerScriptId(trigger_id); 
    73487482} 
    73497483 
     
    73607494    return objmgr.LoadTrinityStrings(db,table,end_value,start_value); 
    73617495} 
     7496 
     7497uint32 TRINITY_DLL_SPEC GetScriptId(const char *name) 
     7498{ 
     7499    return objmgr.GetScriptId(name); 
     7500} 
     7501 
     7502ObjectMgr::ScriptNameMap & GetScriptNames() 
     7503{ 
     7504    return objmgr.GetScriptNames(); 
     7505}