diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/bindings/interface/ScriptMgr.cpp | 109 | ||||
-rw-r--r-- | src/bindings/interface/ScriptMgr.h | 54 | ||||
-rw-r--r-- | src/bindings/interface/Scripts/sc_default.cpp | 14 | ||||
-rw-r--r-- | src/framework/Platform/Define.h | 12 |
5 files changed, 98 insertions, 92 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 352f5aa450d..58ed61a13c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,7 @@ if(DO_SCRIPTS) message("* With Trinity Scripts") SET(SCRIPT_LIB trinityscript) SET(SCRIPT_INCLUDE src/bindings/scripts/include) +ADD_DEFINITIONS(-DDO_SCRIPTS) else (DO_SCRIPTS) message("* Without Trinity Scripts") SET(SCRIPT_LIB trinityinterface) diff --git a/src/bindings/interface/ScriptMgr.cpp b/src/bindings/interface/ScriptMgr.cpp index 57e6ea7c224..5b38352769c 100644 --- a/src/bindings/interface/ScriptMgr.cpp +++ b/src/bindings/interface/ScriptMgr.cpp @@ -26,11 +26,8 @@ #include "Map.h" #include "ObjectMgr.h" -//uint8 loglevel = 0; -int nrscripts; +int num_sc_scripts; Script *m_scripts[MAX_SCRIPTS]; -InstanceDataScript* m_instance_scripts[MAX_INSTANCE_SCRIPTS]; -int num_inst_scripts; // -- Scripts to be added -- extern void AddSC_default(); @@ -39,26 +36,18 @@ extern void AddSC_default(); TRINITY_DLL_EXPORT void ScriptsFree() { // Free resources before library unload - for(int i=0;i<nrscripts;i++) + for(int i = 0; i < num_sc_scripts; 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; + num_sc_scripts = 0; } TRINITY_DLL_EXPORT void ScriptsInit(char const* cfg_file = "trinitycore.conf") { - nrscripts = 0; - num_inst_scripts = 0; + num_sc_scripts = 0; for(int i=0;i<MAX_SCRIPTS;i++) - { - m_scripts[i]=NULL; - m_instance_scripts[i]=NULL; - } + m_scripts[i]=NULL; // -- Inicialize the Scripts to be Added -- AddSC_default(); @@ -78,6 +67,19 @@ Script* GetScriptByName(std::string Name) return NULL; } +//********************************* +//*** Functions used internally *** + +void Script::RegisterSelf() +{ + int id = GetScriptId(Name.c_str()); + if(id) + { + m_scripts[id] = this; + ++num_sc_scripts; + } +} + //******************************** //*** Functions to be Exported *** @@ -86,6 +88,7 @@ char const* ScriptsVersion() { return "Default Trinity scripting library"; } + TRINITY_DLL_EXPORT bool GossipHello ( Player * player, Creature *_Creature ) { @@ -121,6 +124,34 @@ bool GossipSelectWithCode( Player *player, Creature *_Creature, uint32 sender, u } TRINITY_DLL_EXPORT +bool GOSelect( Player *player, GameObject *_GO, uint32 sender, uint32 action ) +{ + if(!_GO) + return false; + debug_log("TSCR: Gossip selection, sender: %d, action: %d",sender, action); + + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; + if(!tmpscript || !tmpscript->pGOSelect) return false; + + player->PlayerTalkClass->ClearMenus(); + return tmpscript->pGOSelect(player,_GO,sender,action); +} + +TRINITY_DLL_EXPORT +bool GOSelectWithCode( Player *player, GameObject *_GO, uint32 sender, uint32 action, const char* sCode ) +{ + if(!_GO) + return false; + debug_log("TSCR: Gossip selection, sender: %d, action: %d",sender, action); + + Script *tmpscript = m_scripts[_GO->GetGOInfo()->ScriptId]; + if(!tmpscript || !tmpscript->pGOSelectWithCode) return false; + + player->PlayerTalkClass->ClearMenus(); + return tmpscript->pGOSelectWithCode(player,_GO,sender,action,sCode); +} + +TRINITY_DLL_EXPORT bool QuestAccept( Player *player, Creature *_Creature, Quest const *_Quest ) { Script *tmpscript = m_scripts[_Creature->GetScriptId()]; @@ -266,7 +297,7 @@ bool ReceiveEmote( Player *player, Creature *_Creature, uint32 emote ) return tmpscript->pReceiveEmote(player, _Creature, emote); } -/*TRINITY_DLL_EXPORT +TRINITY_DLL_EXPORT InstanceData* CreateInstanceData(Map *map) { if (!map->IsDungeon()) return NULL; @@ -277,47 +308,3 @@ InstanceData* CreateInstanceData(Map *map) return tmpscript->GetInstanceData(map); } -void ScriptedAI::UpdateAI(const uint32) -{ - //Check if we have a current target - if( m_creature->isAlive() && m_creature->SelectHostilTarget() && m_creature->getVictim()) - { - //If we are within range melee the target - if( m_creature->IsWithinDistInMap(m_creature->getVictim(), ATTACK_DISTANCE)) - { - if( m_creature->isAttackReady() ) - { - m_creature->AttackerStateUpdate(m_creature->getVictim()); - m_creature->resetAttackTimer(); - } - } - } -} - -void ScriptedAI::EnterEvadeMode() -{ - if( m_creature->isAlive() ) - DoGoHome(); -} - -void ScriptedAI::DoStartAttack(Unit* victim) -{ - if( m_creature->Attack(victim, true) ) - m_creature->GetMotionMaster()->MoveChase(victim); -} - -void ScriptedAI::DoStopAttack() -{ - if( m_creature->getVictim() != NULL ) - { - m_creature->AttackStop(); - } -} - -void ScriptedAI::DoGoHome() -{ - if( !m_creature->getVictim() && m_creature->isAlive() ) - m_creature->GetMotionMaster()->MoveTargetedHome(); -} -*/ - diff --git a/src/bindings/interface/ScriptMgr.h b/src/bindings/interface/ScriptMgr.h index 8c6c91ec362..f0a856ccc35 100644 --- a/src/bindings/interface/ScriptMgr.h +++ b/src/bindings/interface/ScriptMgr.h @@ -35,12 +35,11 @@ class SpellCastTargets; class Map; #define MAX_SCRIPTS 1000 -#define MAX_INSTANCE_SCRIPTS 1000 struct Script { Script() : - pGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGossipSelectWithCode(NULL), + pGossipHello(NULL), pQuestAccept(NULL), pGossipSelect(NULL), pGossipSelectWithCode(NULL), pGOSelect(NULL), pGOSelectWithCode(NULL), pQuestSelect(NULL), pQuestComplete(NULL), pNPCDialogStatus(NULL), pGODialogStatus(NULL), pChooseReward(NULL), pItemHello(NULL), pGOHello(NULL), pAreaTrigger(NULL), pItemQuestAccept(NULL), pGOQuestAccept(NULL), pGOChooseReward(NULL), pReceiveEmote(NULL), pItemUse(NULL), GetAI(NULL) @@ -49,26 +48,30 @@ struct Script std::string Name; // -- Quest/gossip Methods to be scripted -- - bool (*pGossipHello )(Player *player, Creature *_Creature); - bool (*pQuestAccept )(Player *player, Creature *_Creature, Quest const*_Quest ); - bool (*pGossipSelect )(Player *player, Creature *_Creature, uint32 sender, uint32 action ); - bool (*pGossipSelectWithCode)(Player *player, Creature *_Creature, uint32 sender, uint32 action, const char* sCode ); - bool (*pQuestSelect )(Player *player, Creature *_Creature, Quest const*_Quest ); - bool (*pQuestComplete )(Player *player, Creature *_Creature, Quest const*_Quest ); - uint32 (*pNPCDialogStatus )(Player *player, Creature *_Creature ); - uint32 (*pGODialogStatus )(Player *player, GameObject * _GO ); - bool (*pChooseReward )(Player *player, Creature *_Creature, Quest const*_Quest, uint32 opt ); - bool (*pItemHello )(Player *player, Item *_Item, Quest const*_Quest ); - bool (*pGOHello )(Player *player, GameObject *_GO ); - bool (*pAreaTrigger )(Player *player, AreaTriggerEntry* at); - bool (*pItemQuestAccept )(Player *player, Item *_Item, Quest const*_Quest ); - bool (*pGOQuestAccept )(Player *player, GameObject *_GO, Quest const*_Quest ); - bool (*pGOChooseReward )(Player *player, GameObject *_GO, Quest const*_Quest, uint32 opt ); - bool (*pReceiveEmote )(Player *player, Creature *_Creature, uint32 emote ); - bool (*pItemUse )(Player *player, Item* _Item, SpellCastTargets const& targets); - - CreatureAI* (*GetAI)(Creature *_Creature); - // ----------------------------------------- + bool (*pGossipHello )(Player*, Creature*); + bool (*pQuestAccept )(Player*, Creature*, Quest const*); + bool (*pGossipSelect )(Player*, Creature*, uint32, uint32); + bool (*pGossipSelectWithCode)(Player*, Creature*, uint32, uint32, const char*); + bool (*pGOSelect )(Player*, GameObject*, uint32, uint32); + bool (*pGOSelectWithCode )(Player*, GameObject*, uint32, uint32, const char*); + bool (*pQuestSelect )(Player*, Creature*, Quest const*); + bool (*pQuestComplete )(Player*, Creature*, Quest const*); + uint32 (*pNPCDialogStatus )(Player*, Creature*); + uint32 (*pGODialogStatus )(Player*, GameObject*); + bool (*pChooseReward )(Player*, Creature*, Quest const*, uint32); + bool (*pItemHello )(Player*, Item*, Quest const*); + bool (*pGOHello )(Player*, GameObject*); + bool (*pAreaTrigger )(Player*, AreaTriggerEntry*); + bool (*pItemQuestAccept )(Player*, Item*, Quest const*); + bool (*pGOQuestAccept )(Player*, GameObject*, Quest const*); + bool (*pGOChooseReward )(Player*, GameObject*, Quest const*, uint32); + bool (*pReceiveEmote )(Player*, Creature*, uint32); + bool (*pItemUse )(Player*, Item*, SpellCastTargets const&); + + CreatureAI* (*GetAI)(Creature*); + InstanceData* (*GetInstanceData)(Map*); + + void RegisterSelf(); }; @@ -81,11 +84,6 @@ class InstanceDataScript 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) struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI @@ -152,7 +150,7 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI void DoSay(char const* text, uint32 language) { - m_creature->Say(text,language,0); + m_creature->MonsterSay(text,language,0); } void DoGoHome(); diff --git a/src/bindings/interface/Scripts/sc_default.cpp b/src/bindings/interface/Scripts/sc_default.cpp index 495de39c270..88b1414ce05 100644 --- a/src/bindings/interface/Scripts/sc_default.cpp +++ b/src/bindings/interface/Scripts/sc_default.cpp @@ -35,6 +35,16 @@ bool GossipSelectWithCode_default( Player* /*player*/, Creature* /*_Creature*/, return false; } +bool GOSelect_default(Player* /*player*/, GameObject* /*_GO*/, uint32 /*sender*/, uint32 /*action*/) +{ + return false; +} + +bool GOSelectWithCode_default(Player* /*player*/, GameObject* /*_GO*/, uint32 /*sender*/, uint32 /*action*/, const char* /*sCode*/) +{ + return false; +} + bool QuestAccept_default(Player* /*player*/, Creature* /*_Creature*/, Quest const* /*_Quest*/ ) { return false; @@ -105,6 +115,8 @@ void AddSC_default() newscript->pQuestAccept = &QuestAccept_default; newscript->pGossipSelect = &GossipSelect_default; newscript->pGossipSelectWithCode = &GossipSelectWithCode_default; + newscript->pGOSelect = &GOSelect_default; + newscript->pGOSelectWithCode = &GOSelectWithCode_default; newscript->pQuestSelect = &QuestSelect_default; newscript->pQuestComplete = &QuestComplete_default; newscript->pNPCDialogStatus = &NPCDialogStatus_default; @@ -117,6 +129,6 @@ void AddSC_default() newscript->pGOQuestAccept = &GOQuestAccept_default; newscript->pGOChooseReward = &GOChooseReward_default; - m_scripts[nrscripts++] = newscript; + newscript->RegisterSelf(); } diff --git a/src/framework/Platform/Define.h b/src/framework/Platform/Define.h index 5e0cdfdd179..ac0435b62a4 100644 --- a/src/framework/Platform/Define.h +++ b/src/framework/Platform/Define.h @@ -62,10 +62,18 @@ # endif //__APPLE_CC__ && BIG_ENDIAN # if defined(__APPLE_CC__) # define TRINITY_SCRIPT_EXT ".dylib" -# define TRINITY_SCRIPT_NAME "../lib/libtrinityscript" +# if defined(DO_SCRIPTS) +# define TRINITY_SCRIPT_NAME "../lib/libtrinityscript" +# else +# define TRINITY_SCRIPT_NAME "../lib/libtrinityinterface" +# endif // DO_SCRIPTS # else # define TRINITY_SCRIPT_EXT ".so" -# define TRINITY_SCRIPT_NAME "libtrinityscript" +# if defined(DO_SCRIPTS) +# define TRINITY_SCRIPT_NAME "libtrinityscript" +# else +# define TRINITY_SCRIPT_NAME "libtrinityinterface" +# endif // DO_SCRIPTS # endif //__APPLE_CC__ # define TRINITY_PATH_MAX PATH_MAX #endif //PLATFORM |