Skip to content

Commit

Permalink
[sd2_mr0706] Extend AutoScript
Browse files Browse the repository at this point in the history
  • Loading branch information
boxa committed Aug 18, 2014
1 parent 0a9aeda commit 3c22808
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
15 changes: 11 additions & 4 deletions ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void InitScriptLibrary()
* @param pSource Source of the text
* @param pTarget Can be NULL (depending on CHAT_TYPE of iTextEntry). Possible target for the text
*/
void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget)
void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget/*=NULL*/)
{
if (!pSource)
{
Expand All @@ -182,8 +182,8 @@ void DoScriptText(int32 iTextEntry, WorldObject* pSource, Unit* pTarget)

if (iTextEntry >= 0)
{
script_error_log("DoScriptText with source entry %u (TypeId=%u, guid=%u) attempts to process text entry %i, but text entry must be negative.",
pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), iTextEntry);
script_error_log("DoScriptText with source %s attempts to process text entry %i, but text entry must be negative.",
pSource->GetGuidStr().c_str(), iTextEntry);

return;
}
Expand Down Expand Up @@ -269,7 +269,7 @@ void Script::RegisterSelf(bool bReportError)
//*********************************
//******** AutoScript *************

Script* AutoScript::newScript(const char* scriptName, bool reportError/*=true*/)
Script* AutoScript::newScript(char const* scriptName, bool reportError /*=true*/)
{
Register(); // register last added script (if any)

Expand All @@ -278,6 +278,13 @@ Script* AutoScript::newScript(const char* scriptName, bool reportError/*=true*/)
return m_script;
}

Script* AutoScript::newScript(char const* scriptName, TGetAI getAIPtr, bool reportError /*= true*/)
{
newScript(scriptName, reportError);
m_script->GetAI = getAIPtr;
return m_script;
}

void AutoScript::Register()
{
if (!m_script)
Expand Down
15 changes: 11 additions & 4 deletions ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ enum EscortFaction

struct Script
{
Script(const char* scriptName = NULL) : Name(scriptName),
Script(char const* scriptName = NULL) : Name(scriptName),
pGossipHello(NULL), pGossipHelloGO(NULL), pGossipSelect(NULL), pGossipSelectGO(NULL),
pGossipSelectWithCode(NULL), pGossipSelectGOWithCode(NULL),
pDialogStatusNPC(NULL), pDialogStatusGO(NULL),
Expand All @@ -73,7 +73,7 @@ struct Script
pEffectAuraDummy(NULL), GetAI(NULL), GetInstanceData(NULL)
{}

const char* Name;
char const* Name;

bool (*pGossipHello )(Player*, Creature*);
bool (*pGossipHelloGO )(Player*, GameObject*);
Expand Down Expand Up @@ -108,6 +108,9 @@ struct Script
// *********************************************************
// ******************* AutoScript **************************

typedef CreatureAI* (*TGetAI)(Creature*);
typedef InstanceData* (*TGetInstanceData)(Map*);

class AutoScript
{
private:
Expand All @@ -118,10 +121,14 @@ class AutoScript

public:
AutoScript() : m_script(NULL), m_reportError(true) {}
AutoScript(const char* scriptName, bool reportError = true) : m_script(NULL) { newScript(scriptName, reportError); }
AutoScript(char const* scriptName, bool reportError = true) : m_script(NULL) { newScript(scriptName, reportError); }
AutoScript(char const* scriptName, TGetAI getAIPtr, bool reportError = true) : m_script(NULL) { newScript(scriptName, reportError); m_script->GetAI = getAIPtr; }
AutoScript(char const* scriptName, TGetInstanceData getIDPtr, bool reportError = true) : m_script(NULL) { newScript(scriptName, reportError); m_script->GetInstanceData = getIDPtr; }

~AutoScript() { Register(); }

Script* newScript(const char* scriptName, bool reportError = true);
Script* newScript(char const* scriptName, bool reportError = true);
Script* newScript(char const* scriptName, TGetAI getAIPtr, bool reportError = true);

Script* operator -> ()
{
Expand Down
2 changes: 1 addition & 1 deletion sd2_revision_R2.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __SD2_REVISION_R2_H__
#define __SD2_REVISION_R2_H__
#define SD2_REVISION_R2 "0705"
#define SD2_REVISION_R2 "0706"
#endif // __SD2_REVISION_R2_H__

0 comments on commit 3c22808

Please sign in to comment.