mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 01:37:00 +00:00
[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:
parent
074bd3a08f
commit
766654c85d
16 changed files with 184 additions and 101 deletions
|
|
@ -27,8 +27,6 @@
|
|||
//uint8 loglevel = 0;
|
||||
int nrscripts;
|
||||
Script *m_scripts[MAX_SCRIPTS];
|
||||
InstanceDataScript* m_instance_scripts[MAX_INSTANCE_SCRIPTS];
|
||||
int num_inst_scripts;
|
||||
|
||||
// -- Scripts to be added --
|
||||
extern void AddSC_default();
|
||||
|
|
@ -40,22 +38,16 @@ void ScriptsFree()
|
|||
for(int i=0;i<nrscripts;i++)
|
||||
delete m_scripts[i];
|
||||
|
||||
for(int i=0;i<num_inst_scripts;i++)
|
||||
delete m_instance_scripts[i];
|
||||
|
||||
nrscripts = 0;
|
||||
num_inst_scripts = 0;
|
||||
}
|
||||
|
||||
MANGOS_DLL_EXPORT
|
||||
void ScriptsInit()
|
||||
{
|
||||
nrscripts = 0;
|
||||
num_inst_scripts = 0;
|
||||
nrscripts = GetScriptNames().size();
|
||||
for(int i=0;i<MAX_SCRIPTS;i++)
|
||||
{
|
||||
m_scripts[i]=NULL;
|
||||
m_instance_scripts[i]=NULL;
|
||||
}
|
||||
|
||||
// -- Inicialize the Scripts to be Added --
|
||||
|
|
@ -70,22 +62,16 @@ char const* ScriptsVersion()
|
|||
return "Default MaNGOS scripting library";
|
||||
}
|
||||
|
||||
Script* GetScriptByName(std::string Name)
|
||||
void Script::registerSelf()
|
||||
{
|
||||
if(Name.empty())
|
||||
return NULL;
|
||||
for(int i=0;i<MAX_SCRIPTS;i++)
|
||||
{
|
||||
if( m_scripts[i] && m_scripts[i]->Name == Name )
|
||||
return m_scripts[i];
|
||||
}
|
||||
return NULL;
|
||||
int id = GetScriptId(Name.c_str());
|
||||
if(id != 0) m_scripts[id] = this;
|
||||
}
|
||||
|
||||
MANGOS_DLL_EXPORT
|
||||
bool GossipHello ( Player * player, Creature *_Creature )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if(!tmpscript || !tmpscript->pGossipHello) return false;
|
||||
|
||||
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);
|
||||
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if(!tmpscript || !tmpscript->pGossipSelect) return false;
|
||||
|
||||
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);
|
||||
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if(!tmpscript || !tmpscript->pGossipSelectWithCode) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -119,7 +105,7 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u
|
|||
MANGOS_DLL_EXPORT
|
||||
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;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -129,7 +115,7 @@ bool QuestAccept( Player *player, Creature *_Creature, Quest *_Quest )
|
|||
MANGOS_DLL_EXPORT
|
||||
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;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -139,7 +125,7 @@ bool QuestSelect( Player *player, Creature *_Creature, Quest *_Quest )
|
|||
MANGOS_DLL_EXPORT
|
||||
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;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -149,7 +135,7 @@ bool QuestComplete( Player *player, Creature *_Creature, Quest *_Quest )
|
|||
MANGOS_DLL_EXPORT
|
||||
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;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -159,7 +145,7 @@ bool ChooseReward( Player *player, Creature *_Creature, Quest *_Quest, uint32 op
|
|||
MANGOS_DLL_EXPORT
|
||||
uint32 NPCDialogStatus( Player *player, Creature *_Creature )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if(!tmpscript || !tmpscript->pNPCDialogStatus) return 100;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -171,7 +157,7 @@ uint32 GODialogStatus( Player *player, GameObject *_GO )
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if(!tmpscript || !tmpscript->pGODialogStatus) return 100;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -183,7 +169,7 @@ bool ItemHello( Player *player, Item *_Item, Quest *_Quest )
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(_Item->GetProto()->ScriptName);
|
||||
tmpscript = m_scripts[_Item->GetProto()->ScriptId];
|
||||
if(!tmpscript || !tmpscript->pItemHello) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -195,7 +181,7 @@ bool ItemQuestAccept( Player *player, Item *_Item, Quest *_Quest )
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(_Item->GetProto()->ScriptName);
|
||||
tmpscript = m_scripts[_Item->GetProto()->ScriptId];
|
||||
if(!tmpscript || !tmpscript->pItemQuestAccept) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -207,7 +193,7 @@ bool GOHello( Player *player, GameObject *_GO )
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if(!tmpscript || !tmpscript->pGOHello) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -219,7 +205,7 @@ bool GOQuestAccept( Player *player, GameObject *_GO, Quest *_Quest )
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if(!tmpscript || !tmpscript->pGOQuestAccept) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -231,7 +217,7 @@ bool GOChooseReward( Player *player, GameObject *_GO, Quest *_Quest, uint32 opt
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(_GO->GetGOInfo()->ScriptName);
|
||||
tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId];
|
||||
if(!tmpscript || !tmpscript->pGOChooseReward) return false;
|
||||
|
||||
player->PlayerTalkClass->ClearMenus();
|
||||
|
|
@ -243,7 +229,7 @@ bool AreaTrigger ( Player *player, AreaTriggerEntry* atEntry )
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(GetAreaTriggerScriptNameById(atEntry->id));
|
||||
tmpscript = m_scripts[GetAreaTriggerScriptId(atEntry->id)];
|
||||
if(!tmpscript || !tmpscript->pAreaTrigger) return false;
|
||||
|
||||
return tmpscript->pAreaTrigger(player, atEntry);
|
||||
|
|
@ -252,7 +238,7 @@ bool AreaTrigger ( Player *player, AreaTriggerEntry* atEntry )
|
|||
MANGOS_DLL_EXPORT
|
||||
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;
|
||||
|
||||
return tmpscript->pReceiveEmote(player,_Creature, emote);
|
||||
|
|
@ -263,7 +249,7 @@ bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets)
|
|||
{
|
||||
Script *tmpscript = NULL;
|
||||
|
||||
tmpscript = GetScriptByName(_Item->GetProto()->ScriptName);
|
||||
tmpscript = m_scripts[_Item->GetProto()->ScriptId];
|
||||
if(!tmpscript || !tmpscript->pItemUse) return false;
|
||||
|
||||
return tmpscript->pItemUse(player,_Item,targets);
|
||||
|
|
@ -272,7 +258,7 @@ bool ItemUse( Player *player, Item* _Item, SpellCastTargets const& targets)
|
|||
MANGOS_DLL_EXPORT
|
||||
CreatureAI* GetAI(Creature *_Creature )
|
||||
{
|
||||
Script *tmpscript = GetScriptByName(_Creature->GetScriptName());
|
||||
Script *tmpscript = m_scripts[_Creature->GetScriptId()];
|
||||
if(!tmpscript || !tmpscript->GetAI) return NULL;
|
||||
|
||||
return tmpscript->GetAI(_Creature);
|
||||
|
|
@ -282,12 +268,10 @@ MANGOS_DLL_EXPORT
|
|||
InstanceData* CreateInstanceData(Map *map)
|
||||
{
|
||||
if(!map->IsDungeon()) return NULL;
|
||||
std::string name = ((InstanceMap*)map)->GetScript();
|
||||
if(!name.empty())
|
||||
for(int i=0;i<num_inst_scripts;i++)
|
||||
if(m_instance_scripts[i] && m_instance_scripts[i]->name == name)
|
||||
return m_instance_scripts[i]->GetInstanceData(map);
|
||||
return NULL;
|
||||
Script *tmpscript = m_scripts[((InstanceMap*)map)->GetScriptId()];
|
||||
if(!tmpscript || !tmpscript->GetInstanceData) return NULL;
|
||||
|
||||
return tmpscript->GetInstanceData(map);
|
||||
}
|
||||
|
||||
void ScriptedAI::UpdateAI(const uint32)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue