[6828] Added script name indexing for creature, gameobject, item, areatrigger and instance scripts.

* loaded all distinct script names into one vector at server startup
* added custom loaders to convert the script names to indices
* converted all the script lookup functions to use the index instead of the name
This commit is contained in:
Wyk3d 2008-11-16 03:18:26 +02:00
parent 074bd3a08f
commit 766654c85d
16 changed files with 184 additions and 101 deletions

View file

@ -27,8 +27,6 @@
//uint8 loglevel = 0; //uint8 loglevel = 0;
int nrscripts; int nrscripts;
Script *m_scripts[MAX_SCRIPTS]; Script *m_scripts[MAX_SCRIPTS];
InstanceDataScript* m_instance_scripts[MAX_INSTANCE_SCRIPTS];
int num_inst_scripts;
// -- Scripts to be added -- // -- Scripts to be added --
extern void AddSC_default(); extern void AddSC_default();
@ -40,22 +38,16 @@ void ScriptsFree()
for(int i=0;i<nrscripts;i++) for(int i=0;i<nrscripts;i++)
delete m_scripts[i]; delete m_scripts[i];
for(int i=0;i<num_inst_scripts;i++)
delete m_instance_scripts[i];
nrscripts = 0; nrscripts = 0;
num_inst_scripts = 0;
} }
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
void ScriptsInit() void ScriptsInit()
{ {
nrscripts = 0; nrscripts = GetScriptNames().size();
num_inst_scripts = 0;
for(int i=0;i<MAX_SCRIPTS;i++) for(int i=0;i<MAX_SCRIPTS;i++)
{ {
m_scripts[i]=NULL; m_scripts[i]=NULL;
m_instance_scripts[i]=NULL;
} }
// -- Inicialize the Scripts to be Added -- // -- Inicialize the Scripts to be Added --
@ -70,22 +62,16 @@ char const* ScriptsVersion()
return "Default MaNGOS scripting library"; return "Default MaNGOS scripting library";
} }
Script* GetScriptByName(std::string Name) void Script::registerSelf()
{ {
if(Name.empty()) int id = GetScriptId(Name.c_str());
return NULL; if(id != 0) m_scripts[id] = this;
for(int i=0;i<MAX_SCRIPTS;i++)
{
if( m_scripts[i] && m_scripts[i]->Name == Name )
return m_scripts[i];
}
return NULL;
} }
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
bool GossipHello ( Player * player, Creature *_Creature ) bool GossipHello ( Player * player, Creature *_Creature )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pGossipHello) return false; if(!tmpscript || !tmpscript->pGossipHello) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -97,7 +83,7 @@ bool GossipSelect( Player *player, Creature *_Creature,uint32 sender, uint32 act
{ {
debug_log("DEBUG: Gossip selection, sender: %d, action: %d",sender, action); debug_log("DEBUG: Gossip selection, sender: %d, action: %d",sender, action);
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pGossipSelect) return false; if(!tmpscript || !tmpscript->pGossipSelect) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -109,7 +95,7 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u
{ {
debug_log("DEBUG: Gossip selection, sender: %d, action: %d",sender, action); debug_log("DEBUG: Gossip selection, sender: %d, action: %d",sender, action);
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pGossipSelectWithCode) return false; if(!tmpscript || !tmpscript->pGossipSelectWithCode) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -119,7 +105,7 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
bool QuestAccept( Player *player, Creature *_Creature, Quest *_Quest ) bool QuestAccept( Player *player, Creature *_Creature, Quest *_Quest )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pQuestAccept) return false; if(!tmpscript || !tmpscript->pQuestAccept) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -129,7 +115,7 @@ bool QuestAccept( Player *player, Creature *_Creature, Quest *_Quest )
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
bool QuestSelect( Player *player, Creature *_Creature, Quest *_Quest ) bool QuestSelect( Player *player, Creature *_Creature, Quest *_Quest )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pQuestSelect) return false; if(!tmpscript || !tmpscript->pQuestSelect) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -139,7 +125,7 @@ bool QuestSelect( Player *player, Creature *_Creature, Quest *_Quest )
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
bool QuestComplete( Player *player, Creature *_Creature, Quest *_Quest ) bool QuestComplete( Player *player, Creature *_Creature, Quest *_Quest )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pQuestComplete) return false; if(!tmpscript || !tmpscript->pQuestComplete) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -149,7 +135,7 @@ bool QuestComplete( Player *player, Creature *_Creature, Quest *_Quest )
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
bool ChooseReward( Player *player, Creature *_Creature, Quest *_Quest, uint32 opt ) bool ChooseReward( Player *player, Creature *_Creature, Quest *_Quest, uint32 opt )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pChooseReward) return false; if(!tmpscript || !tmpscript->pChooseReward) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -159,7 +145,7 @@ bool ChooseReward( Player *player, Creature *_Creature, Quest *_Quest, uint32 op
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
uint32 NPCDialogStatus( Player *player, Creature *_Creature ) uint32 NPCDialogStatus( Player *player, Creature *_Creature )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pNPCDialogStatus) return 100; if(!tmpscript || !tmpscript->pNPCDialogStatus) return 100;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -171,7 +157,7 @@ uint32 GODialogStatus( Player *player, GameObject *_GO )
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
if(!tmpscript || !tmpscript->pGODialogStatus) return 100; if(!tmpscript || !tmpscript->pGODialogStatus) return 100;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -183,7 +169,7 @@ bool ItemHello( Player *player, Item *_Item, Quest *_Quest )
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); tmpscript = m_scripts[_Item->GetProto()->ScriptId];
if(!tmpscript || !tmpscript->pItemHello) return false; if(!tmpscript || !tmpscript->pItemHello) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -195,7 +181,7 @@ bool ItemQuestAccept( Player *player, Item *_Item, Quest *_Quest )
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); tmpscript = m_scripts[_Item->GetProto()->ScriptId];
if(!tmpscript || !tmpscript->pItemQuestAccept) return false; if(!tmpscript || !tmpscript->pItemQuestAccept) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -207,7 +193,7 @@ bool GOHello( Player *player, GameObject *_GO )
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
if(!tmpscript || !tmpscript->pGOHello) return false; if(!tmpscript || !tmpscript->pGOHello) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -219,7 +205,7 @@ bool GOQuestAccept( Player *player, GameObject *_GO, Quest *_Quest )
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
if(!tmpscript || !tmpscript->pGOQuestAccept) return false; if(!tmpscript || !tmpscript->pGOQuestAccept) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -231,7 +217,7 @@ bool GOChooseReward( Player *player, GameObject *_GO, Quest *_Quest, uint32 opt
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName); tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
if(!tmpscript || !tmpscript->pGOChooseReward) return false; if(!tmpscript || !tmpscript->pGOChooseReward) return false;
player->PlayerTalkClass->ClearMenus(); player->PlayerTalkClass->ClearMenus();
@ -243,7 +229,7 @@ bool AreaTrigger ( Player *player, AreaTriggerEntry* atEntry )
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(GetAreaTriggerScriptNameById(atEntry->id)); tmpscript = m_scripts[GetAreaTriggerScriptId(atEntry->id)];
if(!tmpscript || !tmpscript->pAreaTrigger) return false; if(!tmpscript || !tmpscript->pAreaTrigger) return false;
return tmpscript->pAreaTrigger(player, atEntry); return tmpscript->pAreaTrigger(player, atEntry);
@ -252,7 +238,7 @@ bool AreaTrigger ( Player *player, AreaTriggerEntry* atEntry )
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
bool ReceiveEmote ( Player *player, Creature *_Creature, uint32 emote ) bool ReceiveEmote ( Player *player, Creature *_Creature, uint32 emote )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->pReceiveEmote) return false; if(!tmpscript || !tmpscript->pReceiveEmote) return false;
return tmpscript->pReceiveEmote(player,_Creature, emote); return tmpscript->pReceiveEmote(player,_Creature, emote);
@ -263,7 +249,7 @@ bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets)
{ {
Script *tmpscript = NULL; Script *tmpscript = NULL;
tmpscript = GetScriptByName(_Item->GetProto()->ScriptName); tmpscript = m_scripts[_Item->GetProto()->ScriptId];
if(!tmpscript || !tmpscript->pItemUse) return false; if(!tmpscript || !tmpscript->pItemUse) return false;
return tmpscript->pItemUse(player,_Item,targets); return tmpscript->pItemUse(player,_Item,targets);
@ -272,7 +258,7 @@ bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets)
MANGOS_DLL_EXPORT MANGOS_DLL_EXPORT
CreatureAI* GetAI(Creature *_Creature ) CreatureAI* GetAI(Creature *_Creature )
{ {
Script *tmpscript = GetScriptByName(_Creature->GetScriptName()); Script *tmpscript = m_scripts[_Creature->GetScriptId()];
if(!tmpscript || !tmpscript->GetAI) return NULL; if(!tmpscript || !tmpscript->GetAI) return NULL;
return tmpscript->GetAI(_Creature); return tmpscript->GetAI(_Creature);
@ -282,12 +268,10 @@ MANGOS_DLL_EXPORT
InstanceData* CreateInstanceData(Map *map) InstanceData* CreateInstanceData(Map *map)
{ {
if(!map->IsDungeon()) return NULL; if(!map->IsDungeon()) return NULL;
std::string name = ((InstanceMap*)map)->GetScript(); Script *tmpscript = m_scripts[((InstanceMap*)map)->GetScriptId()];
if(!name.empty()) if(!tmpscript || !tmpscript->GetInstanceData) return NULL;
for(int i=0;i<num_inst_scripts;i++)
if(m_instance_scripts[i] && m_instance_scripts[i]->name == name) return tmpscript->GetInstanceData(map);
return m_instance_scripts[i]->GetInstanceData(map);
return NULL;
} }
void ScriptedAI::UpdateAI(const uint32) void ScriptedAI::UpdateAI(const uint32)

View file

@ -66,24 +66,12 @@ struct Script
bool (*pItemUse )(Player *player, Item* _Item, SpellCastTargets const& targets); bool (*pItemUse )(Player *player, Item* _Item, SpellCastTargets const& targets);
CreatureAI* (*GetAI)(Creature *_Creature); CreatureAI* (*GetAI)(Creature *_Creature);
InstanceData* (*GetInstanceData)(Map*);
// ----------------------------------------- // -----------------------------------------
void registerSelf();
}; };
class InstanceDataScript
{
public:
InstanceDataScript() : GetInstanceData(NULL) {};
std::string name;
InstanceData* (*GetInstanceData)(Map *_Map);
};
extern int nrscripts;
extern Script *m_scripts[MAX_SCRIPTS];
extern InstanceDataScript *m_instance_scripts[MAX_INSTANCE_SCRIPTS];
extern int num_inst_scripts;
#define VISIBLE_RANGE (50.0f) #define VISIBLE_RANGE (50.0f)
struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI

View file

@ -115,5 +115,5 @@ void AddSC_default()
newscript->pGOQuestAccept = &GOQuestAccept_default; newscript->pGOQuestAccept = &GOQuestAccept_default;
newscript->pGOChooseReward = &GOChooseReward_default; newscript->pGOChooseReward = &GOChooseReward_default;
m_scripts[nrscripts++] = newscript; newscript->registerSelf();
} }

View file

@ -1942,9 +1942,14 @@ uint32 Creature::getLevelForTarget( Unit const* target ) const
return level; return level;
} }
char const* Creature::GetScriptName() const std::string Creature::GetScriptName()
{ {
return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptName; return objmgr.GetScriptName(GetScriptId());
}
uint32 Creature::GetScriptId()
{
return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptID;
} }
VendorItemData const* Creature::GetVendorItems() const VendorItemData const* Creature::GetVendorItems() const

View file

@ -201,7 +201,7 @@ struct CreatureInfo
uint32 equipmentId; uint32 equipmentId;
uint32 MechanicImmuneMask; uint32 MechanicImmuneMask;
uint32 flags_extra; uint32 flags_extra;
char const* ScriptName; uint32 ScriptID;
// helpers // helpers
SkillType GetRequiredLootSkill() const SkillType GetRequiredLootSkill() const
@ -490,7 +490,9 @@ class MANGOS_DLL_SPEC Creature : public Unit
CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; } CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; }
CreatureDataAddon const* GetCreatureAddon() const; CreatureDataAddon const* GetCreatureAddon() const;
char const* GetScriptName() const;
std::string GetScriptName();
uint32 GetScriptId();
void prepareGossipMenu( Player *pPlayer, uint32 gossipid = 0 ); void prepareGossipMenu( Player *pPlayer, uint32 gossipid = 0 );
void sendPreparedGossip( Player* player ); void sendPreparedGossip( Player* player );

View file

@ -355,7 +355,7 @@ struct GameObjectInfo
uint32 data[24]; uint32 data[24];
} raw; } raw;
}; };
char *ScriptName; uint32 ScriptId;
}; };
struct GameObjectLocale struct GameObjectLocale

View file

@ -538,7 +538,7 @@ struct ItemPrototype
uint32 GemProperties; // id from GemProperties.dbc uint32 GemProperties; // id from GemProperties.dbc
uint32 RequiredDisenchantSkill; uint32 RequiredDisenchantSkill;
float ArmorDamageModifier; float ArmorDamageModifier;
char* ScriptName; uint32 ScriptId;
uint32 DisenchantID; uint32 DisenchantID;
uint32 FoodType; uint32 FoodType;
uint32 MinMoneyLoot; uint32 MinMoneyLoot;

View file

@ -1626,7 +1626,7 @@ void InstanceMap::CreateInstanceData(bool load)
InstanceTemplate const* mInstance = objmgr.GetInstanceTemplate(GetId()); InstanceTemplate const* mInstance = objmgr.GetInstanceTemplate(GetId());
if (mInstance) if (mInstance)
{ {
i_script = mInstance->script; i_script_id = mInstance->script_id;
i_data = Script->CreateInstanceData(this); i_data = Script->CreateInstanceData(this);
} }
@ -1643,7 +1643,7 @@ void InstanceMap::CreateInstanceData(bool load)
const char* data = fields[0].GetString(); const char* data = fields[0].GetString();
if(data) if(data)
{ {
sLog.outDebug("Loading instance data for `%s` with id %u", i_script.c_str(), i_InstanceId); sLog.outDebug("Loading instance data for `%s` with id %u", objmgr.GetScriptName(i_script_id), i_InstanceId);
i_data->Load(data); i_data->Load(data);
} }
delete result; delete result;
@ -1651,7 +1651,7 @@ void InstanceMap::CreateInstanceData(bool load)
} }
else else
{ {
sLog.outDebug("New instance data, \"%s\" ,initialized!",i_script.c_str()); sLog.outDebug("New instance data, \"%s\" ,initialized!", objmgr.GetScriptName(i_script_id));
i_data->Initialize(); i_data->Initialize();
} }
} }

View file

@ -102,7 +102,7 @@ struct InstanceTemplate
float startLocY; float startLocY;
float startLocZ; float startLocZ;
float startLocO; float startLocO;
char const* script; uint32 script_id;
}; };
enum LevelRequirementVsMode enum LevelRequirementVsMode
@ -329,7 +329,7 @@ class MANGOS_DLL_SPEC InstanceMap : public Map
void Update(const uint32&); void Update(const uint32&);
void CreateInstanceData(bool load); void CreateInstanceData(bool load);
bool Reset(uint8 method); bool Reset(uint8 method);
std::string GetScript() { return i_script; } uint32 GetScriptId() { return i_script_id; }
InstanceData* GetInstanceData() { return i_data; } InstanceData* GetInstanceData() { return i_data; }
void PermBindAllPlayers(Player *player); void PermBindAllPlayers(Player *player);
PlayerList const& GetPlayers() const { return i_Players;} PlayerList const& GetPlayers() const { return i_Players;}
@ -345,7 +345,7 @@ class MANGOS_DLL_SPEC InstanceMap : public Map
bool m_resetAfterUnload; bool m_resetAfterUnload;
bool m_unloadWhenEmpty; bool m_unloadWhenEmpty;
InstanceData* i_data; InstanceData* i_data;
std::string i_script; uint32 i_script_id;
// only online players that are inside the instance currently // only online players that are inside the instance currently
// TODO ? - use the grid instead to access the players // TODO ? - use the grid instead to access the players
PlayerList i_Players; PlayerList i_Players;

View file

@ -19,6 +19,7 @@
#include "Common.h" #include "Common.h"
#include "Database/DatabaseEnv.h" #include "Database/DatabaseEnv.h"
#include "Database/SQLStorage.h" #include "Database/SQLStorage.h"
#include "Database/SQLStorageImpl.h"
#include "Log.h" #include "Log.h"
#include "MapManager.h" #include "MapManager.h"
@ -631,9 +632,19 @@ void ObjectMgr::LoadNpcOptionLocales()
sLog.outString( ">> Loaded %u npc_option locale strings", mNpcOptionLocaleMap.size() ); sLog.outString( ">> Loaded %u npc_option locale strings", mNpcOptionLocaleMap.size() );
} }
struct SQLCreatureLoader : public SQLStorageLoaderBase<SQLCreatureLoader>
{
template<class D>
void convert_from_str(uint32 field_pos, char *src, D &dst)
{
dst = D(objmgr.GetScriptId(src));
}
};
void ObjectMgr::LoadCreatureTemplates() void ObjectMgr::LoadCreatureTemplates()
{ {
sCreatureStorage.Load(); SQLCreatureLoader loader;
loader.Load(sCreatureStorage);
sLog.outString( ">> Loaded %u creature definitions", sCreatureStorage.RecordCount ); sLog.outString( ">> Loaded %u creature definitions", sCreatureStorage.RecordCount );
sLog.outString(); sLog.outString();
@ -1500,9 +1511,19 @@ void ObjectMgr::LoadItemLocales()
sLog.outString( ">> Loaded %u Item locale strings", mItemLocaleMap.size() ); sLog.outString( ">> Loaded %u Item locale strings", mItemLocaleMap.size() );
} }
struct SQLItemLoader : public SQLStorageLoaderBase<SQLItemLoader>
{
template<class D>
void convert_from_str(uint32 field_pos, char *src, D &dst)
{
dst = D(objmgr.GetScriptId(src));
}
};
void ObjectMgr::LoadItemPrototypes() void ObjectMgr::LoadItemPrototypes()
{ {
sItemStorage.Load (); SQLItemLoader loader;
loader.Load(sItemStorage);
sLog.outString( ">> Loaded %u item prototypes", sItemStorage.RecordCount ); sLog.outString( ">> Loaded %u item prototypes", sItemStorage.RecordCount );
sLog.outString(); sLog.outString();
@ -4120,9 +4141,19 @@ void ObjectMgr::LoadPageTextLocales()
sLog.outString( ">> Loaded %u PageText locale strings", mPageTextLocaleMap.size() ); sLog.outString( ">> Loaded %u PageText locale strings", mPageTextLocaleMap.size() );
} }
struct SQLInstanceLoader : public SQLStorageLoaderBase<SQLInstanceLoader>
{
template<class D>
void convert_from_str(uint32 field_pos, char *src, D &dst)
{
dst = D(objmgr.GetScriptId(src));
}
};
void ObjectMgr::LoadInstanceTemplate() void ObjectMgr::LoadInstanceTemplate()
{ {
sInstanceTemplate.Load(); SQLInstanceLoader loader;
loader.Load(sInstanceTemplate);
for(uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++) for(uint32 i = 0; i < sInstanceTemplate.MaxEntry; i++)
{ {
@ -4536,7 +4567,7 @@ void ObjectMgr::LoadAreaTriggerScripts()
Field *fields = result->Fetch(); Field *fields = result->Fetch();
uint32 Trigger_ID = fields[0].GetUInt32(); uint32 Trigger_ID = fields[0].GetUInt32();
std::string scriptName = fields[1].GetCppString(); const char *scriptName = fields[1].GetString();
AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID); AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
if(!atEntry) if(!atEntry)
@ -4544,7 +4575,7 @@ void ObjectMgr::LoadAreaTriggerScripts()
sLog.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID); sLog.outErrorDb("Area trigger (ID:%u) does not exist in `AreaTrigger.dbc`.",Trigger_ID);
continue; continue;
} }
mAreaTriggerScripts[Trigger_ID] = scriptName; mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName);
} while( result->NextRow() ); } while( result->NextRow() );
delete result; delete result;
@ -5350,9 +5381,19 @@ void ObjectMgr::LoadGameObjectLocales()
sLog.outString( ">> Loaded %u gameobject locale strings", mGameObjectLocaleMap.size() ); sLog.outString( ">> Loaded %u gameobject locale strings", mGameObjectLocaleMap.size() );
} }
struct SQLGameObjectLoader : public SQLStorageLoaderBase<SQLGameObjectLoader>
{
template<class D>
void convert_from_str(uint32 field_pos, char *src, D &dst)
{
dst = D(objmgr.GetScriptId(src));
}
};
void ObjectMgr::LoadGameobjectInfo() void ObjectMgr::LoadGameobjectInfo()
{ {
sGOStorage.Load(); SQLGameObjectLoader loader;
loader.Load(sGOStorage);
// some checks // some checks
for(uint32 id = 1; id < sGOStorage.MaxEntry; id++) for(uint32 id = 1; id < sGOStorage.MaxEntry; id++)
@ -6480,12 +6521,12 @@ bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart, DeclinedName const& n
return true; return true;
} }
const char* ObjectMgr::GetAreaTriggerScriptName(uint32 id) uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id)
{ {
AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(id); AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id);
if(i!= mAreaTriggerScripts.end()) if(i!= mAreaTriggerScripts.end())
return i->second.c_str(); return i->second;
return ""; return 0;
} }
// Checks if player meets the condition // Checks if player meets the condition
@ -7196,6 +7237,42 @@ bool ObjectMgr::IsVendorItemValid( uint32 vendor_entry, uint32 item_id, uint32 m
return true; return true;
} }
void ObjectMgr::LoadScriptNames()
{
m_scriptNames.push_back("");
QueryResult *result = WorldDatabase.Query(
"SELECT DISTINCT(ScriptName) FROM creature_template WHERE ScriptName <> '' "
"UNION "
"SELECT DISTINCT(ScriptName) FROM gameobject_template WHERE ScriptName <> '' "
"UNION "
"SELECT DISTINCT(ScriptName) FROM item_template WHERE ScriptName <> '' "
"UNION "
"SELECT DISTINCT(ScriptName) FROM areatrigger_scripts WHERE ScriptName <> '' "
"UNION "
"SELECT DISTINCT(script) FROM instance_template WHERE script <> ''");
if(result)
{
do
{
m_scriptNames.push_back((*result)[0].GetString());
} while (result->NextRow());
delete result;
}
std::sort(m_scriptNames.begin(), m_scriptNames.end());
}
uint32 ObjectMgr::GetScriptId(const char *name)
{
// use binary search to find the script name in the sorted vector
// assume "" is the first element
if(!name) return 0;
ScriptNameMap::const_iterator itr =
std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name);
if(itr == m_scriptNames.end()) return 0;
return itr - m_scriptNames.begin();
}
void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids) void ObjectMgr::CheckScripts(ScriptMapMap const& scripts,std::set<int32>& ids)
{ {
for(ScriptMapMap::const_iterator itrMM = scripts.begin(); itrMM != scripts.end(); ++itrMM) for(ScriptMapMap::const_iterator itrMM = scripts.begin(); itrMM != scripts.end(); ++itrMM)
@ -7234,11 +7311,10 @@ void ObjectMgr::LoadDbScriptStrings()
sLog.outErrorDb( "Table `db_script_string` has unused string id %u", *itr); sLog.outErrorDb( "Table `db_script_string` has unused string id %u", *itr);
} }
// Functions for scripting access // Functions for scripting access
const char* GetAreaTriggerScriptNameById(uint32 id) uint32 GetAreaTriggerScriptId(uint32 trigger_id)
{ {
return objmgr.GetAreaTriggerScriptName(id); return objmgr.GetAreaTriggerScriptId(trigger_id);
} }
bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value, int32 end_value) bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value, int32 end_value)
@ -7253,3 +7329,13 @@ bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value, in
// for scripting localized strings allowed use _only_ negative entries // for scripting localized strings allowed use _only_ negative entries
return objmgr.LoadMangosStrings(db,table,end_value,start_value); return objmgr.LoadMangosStrings(db,table,end_value,start_value);
} }
uint32 MANGOS_DLL_SPEC GetScriptId(const char *name)
{
return objmgr.GetScriptId(name);
}
ObjectMgr::ScriptNameMap & GetScriptNames()
{
return objmgr.GetScriptNames();
}

View file

@ -286,9 +286,10 @@ class ObjectMgr
typedef UNORDERED_MAP<uint32, Quest*> QuestMap; typedef UNORDERED_MAP<uint32, Quest*> QuestMap;
typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap; typedef UNORDERED_MAP<uint32, AreaTrigger> AreaTriggerMap;
typedef UNORDERED_MAP<uint32, std::string> AreaTriggerScriptMap; typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptMap;
typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap; typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillMap;
@ -296,6 +297,8 @@ class ObjectMgr
typedef UNORDERED_MAP<uint32, PetCreateSpellEntry> PetCreateSpellMap; typedef UNORDERED_MAP<uint32, PetCreateSpellEntry> PetCreateSpellMap;
typedef std::vector<std::string> ScriptNameMap;
Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);} Player* GetPlayer(const char* name) const { return ObjectAccessor::Instance().FindPlayerByName(name);}
Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); } Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
@ -460,7 +463,7 @@ class ObjectMgr
AreaTrigger const* GetGoBackTrigger(uint32 Map) const; AreaTrigger const* GetGoBackTrigger(uint32 Map) const;
const char* GetAreaTriggerScriptName(uint32 id); uint32 GetAreaTriggerScriptId(uint32 trigger_id);
ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const ReputationOnKillEntry const* GetReputationOnKilEntry(uint32 id) const
{ {
@ -764,6 +767,10 @@ class ObjectMgr
bool RemoveVendorItem(uint32 entry,uint32 item); bool RemoveVendorItem(uint32 entry,uint32 item);
bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const; bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL ) const;
void LoadScriptNames();
ScriptNameMap &GetScriptNames() { return m_scriptNames; }
const char * GetScriptName(uint32 id) { return id < m_scriptNames.size() ? m_scriptNames[id].c_str() : ""; }
uint32 GetScriptId(const char *name);
protected: protected:
uint32 m_auctionid; uint32 m_auctionid;
uint32 m_mailid; uint32 m_mailid;
@ -825,6 +832,8 @@ class ObjectMgr
GameTeleMap m_GameTeleMap; GameTeleMap m_GameTeleMap;
ScriptNameMap m_scriptNames;
typedef std::vector<LocaleConstant> LocalForIndex; typedef std::vector<LocaleConstant> LocalForIndex;
LocalForIndex m_LocalForIndex; LocalForIndex m_LocalForIndex;
int GetOrNewIndexForLocale(LocaleConstant loc); int GetOrNewIndexForLocale(LocaleConstant loc);
@ -885,7 +894,9 @@ class ObjectMgr
#define objmgr MaNGOS::Singleton<ObjectMgr>::Instance() #define objmgr MaNGOS::Singleton<ObjectMgr>::Instance()
// scripting access functions // scripting access functions
bool MANGOS_DLL_SPEC LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min()); MANGOS_DLL_SPEC bool LoadMangosStrings(DatabaseType& db, char const* table,int32 start_value = -1, int32 end_value = std::numeric_limits<int32>::min());
MANGOS_DLL_SPEC const char* GetAreaTriggerScriptNameById(uint32 id); MANGOS_DLL_SPEC uint32 GetAreaTriggerScriptId(uint32 trigger_id);
MANGOS_DLL_SPEC uint32 GetScriptId(const char *name);
MANGOS_DLL_SPEC ObjectMgr::ScriptNameMap& GetScriptNames();
#endif #endif

View file

@ -91,7 +91,7 @@ bool LoadScriptingModule(char const* libName)
UnloadScriptingModule(); UnloadScriptingModule();
Script=testScript; Script=testScript;
Script->ScriptsInit(); Script->ScriptsInit(objmgr.GetScriptNames());
sWorld.SetScriptsVersion(Script->ScriptsVersion()); sWorld.SetScriptsVersion(Script->ScriptsVersion());

View file

@ -35,7 +35,7 @@ class InstanceData;
bool LoadScriptingModule(char const* libName = ""); bool LoadScriptingModule(char const* libName = "");
void UnloadScriptingModule(); void UnloadScriptingModule();
typedef void(MANGOS_IMPORT * scriptCallScriptsInit) (); typedef void(MANGOS_IMPORT * scriptCallScriptsInit) (const ObjectMgr::ScriptNameMap &scriptNames);
typedef void(MANGOS_IMPORT * scriptCallScriptsFree) (); typedef void(MANGOS_IMPORT * scriptCallScriptsFree) ();
typedef char const* (MANGOS_IMPORT * scriptCallScriptsVersion) (); typedef char const* (MANGOS_IMPORT * scriptCallScriptsVersion) ();

View file

@ -927,6 +927,9 @@ void World::SetInitialWorldSettings()
LoadDBCStores(m_dataPath); LoadDBCStores(m_dataPath);
DetectDBCLang(); DetectDBCLang();
sLog.outString( "Loading Script Names...");
objmgr.LoadScriptNames();
sLog.outString( "Loading InstanceTemplate" ); sLog.outString( "Loading InstanceTemplate" );
objmgr.LoadInstanceTemplate(); objmgr.LoadInstanceTemplate();

View file

@ -25,27 +25,31 @@ extern DatabasePostgre WorldDatabase;
extern DatabaseMysql WorldDatabase; extern DatabaseMysql WorldDatabase;
#endif #endif
const char CreatureInfofmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis"; const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis";
const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiii";
const char CreatureDataAddonInfofmt[]="iiiiiiis"; const char CreatureDataAddonInfofmt[]="iiiiiiis";
const char CreatureModelfmt[]="iffbi"; const char CreatureModelfmt[]="iffbi";
const char CreatureInfoAddonInfofmt[]="iiiiiiis"; const char CreatureInfoAddonInfofmt[]="iiiiiiis";
const char EquipmentInfofmt[]="iiiiiiiiii"; const char EquipmentInfofmt[]="iiiiiiiiii";
const char GameObjectInfofmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis"; const char GameObjectInfosrcfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis";
const char ItemPrototypefmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii"; const char GameObjectInfodstfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiii";
const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii";
const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiii";
const char PageTextfmt[]="isi"; const char PageTextfmt[]="isi";
const char SpellThreatfmt[]="ii"; const char SpellThreatfmt[]="ii";
const char InstanceTemplatefmt[]="iiiiiiffffs"; const char InstanceTemplatesrcfmt[]="iiiiiiffffs";
const char InstanceTemplatedstfmt[]="iiiiiiffffi";
SQLStorage sCreatureStorage(CreatureInfofmt,"entry","creature_template"); SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template");
SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon"); SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon");
SQLStorage sCreatureModelStorage(CreatureModelfmt,"modelid","creature_model_info"); SQLStorage sCreatureModelStorage(CreatureModelfmt,"modelid","creature_model_info");
SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon"); SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon");
SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template"); SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template");
SQLStorage sGOStorage(GameObjectInfofmt,"entry","gameobject_template"); SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template");
SQLStorage sItemStorage(ItemPrototypefmt,"entry","item_template"); SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template");
SQLStorage sPageTextStore(PageTextfmt,"entry","page_text"); SQLStorage sPageTextStore(PageTextfmt,"entry","page_text");
SQLStorage sSpellThreatStore(SpellThreatfmt,"entry","spell_threat"); SQLStorage sSpellThreatStore(SpellThreatfmt,"entry","spell_threat");
SQLStorage sInstanceTemplate(InstanceTemplatefmt,"map","instance_template"); SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map","instance_template");
void SQLStorage::Free () void SQLStorage::Free ()
{ {

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "6827" #define REVISION_NR "6828"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__