Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Change container for 'script_texts'. No longer use scriptname in sc…

…ript text search.

git-svn-id: https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2@647 5f9c896b-1e26-0410-94da-f77f675e2462
  • Loading branch information...
commit 144cab195f739d0c51bf697551b2938f0687e503 1 parent 1e3669a
Ntsc authored
View
105 ScriptMgr.cpp
@@ -20,8 +20,6 @@ HM_NAMESPACE::hash_map<uint32, std::string> EventAI_Text_Map;
// Script Text used as says / yells / text emotes / whispers in scripts.
struct ScriptText
{
- std::string ScriptName;
- uint32 Entry;
uint32 SoundId;
uint8 Type;
uint32 Language;
@@ -39,7 +37,7 @@ enum ChatType
CHAT_TYPE_BOSS_WHISPER = 5,
};
-std::list<ScriptText> ScriptTextList;
+HM_NAMESPACE::hash_map<uint32, ScriptText> Script_TextMap;
// Localized Text structure for storing locales (for EAI and SD2 scripts).
struct Localized_Text
@@ -1038,8 +1036,8 @@ void LoadDatabase()
result = ScriptDev2DB.PQuery("SELECT `scriptname`, `id`, `sound`, `type`, `language`, `text`"
"FROM `script_texts`;");
- // Drop Existing Script Text List
- ScriptTextList.clear();
+ // Drop Existing Script Text Map
+ Script_TextMap.clear();
if(result)
{
@@ -1053,26 +1051,16 @@ void LoadDatabase()
Field* fields = result->Fetch();
ScriptText temp;
- std::string scr = fields[0].GetString();
- uint32 id = fields[1].GetInt32();
- uint32 sound = fields[2].GetInt32();
- uint8 chat = fields[3].GetInt32();
- uint32 lang = fields[4].GetInt32();
- std::string str = fields[5].GetString();
-
- if(!strlen(scr.c_str()))
- error_db_log("SD2: Script Name for Script Text %u is empty!", id);
- if(!strlen(str.c_str()))
- error_db_log("SD2: Script Text %s %u is empty!", scr.c_str(), id);
-
- temp.ScriptName = scr;
- temp.Entry = id;
- temp.SoundId = sound;
- temp.Type = chat;
- temp.Language = lang;
- temp.Text = str;
-
- ScriptTextList.push_back(temp);
+ uint32 i = fields[0].GetInt32();
+ temp.SoundId = fields[1].GetInt32();
+ temp.Type = fields[2].GetInt32();
+ temp.Language = fields[3].GetInt32();
+ temp.Text = fields[4].GetString();
+
+ if(!strlen(temp.Text.c_str()))
+ error_db_log("SD2: Script Text %u is empty!", i);
+
+ Script_TextMap[i] = temp;
++count;
}while(result->NextRow());
@@ -1082,7 +1070,7 @@ void LoadDatabase()
outstring_log("");
outstring_log("SD2: Loaded %u Script Texts", count);
- }else error_db_log("SD2 WARNING >> Loaded 0 Script Texts. Database table `script_texts` is empty.");
+ }else outstring_log("SD2 WARNING >> Loaded 0 Script Texts. Database table `script_texts` is empty.");
//Free database thread and resources
ScriptDev2DB.HaltDelayThread();
@@ -1831,76 +1819,61 @@ const char* GetEventAIText(uint32 entry)
return DEFAULT_TEXT;
}
-void ProcessScriptText(uint32 entry, Creature* pCreature, Unit* target)
-{
- if(!pCreature)
+void ProcessScriptText(uint32 entry, WorldObject* pSource, Unit* target)
+{
+ if (!pSource)
{
- error_log("SD2 ERROR: Unable to process Script Text. Invalid Creature passed");
+ error_log("SD2 ERROR: ProcessScriptText invalid Source pointer.");
return;
}
- uint32 sound = 0;
- uint8 type = 0;
- uint32 lang = 0;
- const char* text = NULL;
+ HM_NAMESPACE::hash_map<uint32, ScriptText>::iterator i = Script_TextMap.find(entry);
- if(ScriptTextList.empty())
+ if (i == Script_TextMap.end())
{
- error_log("SD2 ERROR: Script Text List is empty. Unable to find entry %u for script %s", entry, pCreature->GetScriptName());
+ error_log("SD2 ERROR: ProcessScriptText could not find entry %i.");
return;
}
- std::list<ScriptText>::iterator itr = ScriptTextList.begin();
- for( ; itr != ScriptTextList.end(); ++itr)
- {
- if((*itr).ScriptName == pCreature->GetScriptName() && (*itr).Entry == entry)
- {
- sound = (*itr).SoundId;
- type = (*itr).Type;
- lang = (*itr).Language;
- text = (*itr).Text.c_str();
- }
- }
-
- if(sound)
+ if((*i).second.SoundId)
{
WorldPacket data(4);
data.SetOpcode(SMSG_PLAY_SOUND);
- data << uint32(sound);
- if(pCreature) pCreature->SendMessageToSet(&data, false);
- else target->SendMessageToSet(&data, false);
+ data << uint32((*i).second.SoundId);
+ pSource->SendMessageToSet(&data,false);
}
- if(!text || !strlen(text))
- text = DEFAULT_TEXT;
-
- switch(type)
+ switch((*i).second.Type)
{
case CHAT_TYPE_SAY:
- pCreature->Say(text, lang, target ? target->GetGUID() : 0);
+ pSource->MonsterSay((*i).second.Text.c_str(), (*i).second.Language, target ? target->GetGUID() : 0);
break;
case CHAT_TYPE_YELL:
- pCreature->Yell(text, lang, target ? target->GetGUID() : 0);
+ pSource->MonsterYell((*i).second.Text.c_str(), (*i).second.Language, target ? target->GetGUID() : 0);
break;
case CHAT_TYPE_TEXT_EMOTE:
- pCreature->TextEmote(text, target ? target->GetGUID() : 0);
+ pSource->MonsterTextEmote((*i).second.Text.c_str(), target ? target->GetGUID() : 0);
break;
case CHAT_TYPE_BOSS_EMOTE:
- pCreature->TextEmote(text, target ? target->GetGUID() : 0, true);
+ pSource->MonsterTextEmote((*i).second.Text.c_str(), target ? target->GetGUID() : 0, true);
break;
case CHAT_TYPE_WHISPER:
- if(target) pCreature->Whisper(target->GetGUID(), text);
- else error_log("SD2 ERROR: Unable to process script text whisper %u %s - invalid target", entry, pCreature->GetScriptName());
- break;
+ {
+ if (target)
+ pSource->MonsterWhisper(target->GetGUID(), (*i).second.Text.c_str());
+ else error_log("SD2 ERROR: ProcessScriptText cannot whisper without target unit. Entry %d. ", entry);
+ }break;
case CHAT_TYPE_BOSS_WHISPER:
- if(target) pCreature->Whisper(target->GetGUID(), text, true);
- else error_log("SD2 ERROR: Unable to process script text boss whisper %u %s - invalid target", entry, pCreature->GetScriptName());
- break;
+ {
+ if(target)
+ pSource->MonsterWhisper(target->GetGUID(), (*i).second.Text.c_str(), true);
+ else error_log("SD2 ERROR: ProcessScriptText cannot whsiper without target unit. Entry %d.", entry);
+ }break;
}
}
View
3  ScriptMgr.h
@@ -17,6 +17,7 @@ class GameObject;
class SpellCastTargets;
class Map;
class Unit;
+class WorldObject;
#define MAX_SCRIPTS 5000 //72 bytes each (approx 351kb)
@@ -72,7 +73,7 @@ const char* GetScriptLocalizedText(uint32 entry);
const char* GetEventAIText(uint32 entry); // TODO: Locales
// Script Text function
-void ProcessScriptText(uint32 entry, Creature* pCreature, Unit* target = NULL); // TODO: Locales
+void ProcessScriptText(uint32 entry, WorldObject* pSource, Unit* target = NULL); // TODO: Locales
#if COMPILER == COMPILER_GNU
#define FUNC_PTR(name,callconvention,returntype,parameters) typedef returntype(*name)parameters __attribute__ ((callconvention));
View
3  sql/Updates/Makefile.am
@@ -208,4 +208,5 @@ pkgdata_DATA = \
r639_mangos.sql \
r642_mangos.sql \
r643_mangos.sql \
- r646_mangos.sql
+ r646_mangos.sql \
+ r647_scriptdev2.sql
View
10 sql/Updates/r647_scriptdev2.sql
@@ -0,0 +1,10 @@
+DROP TABLE IF EXISTS `script_texts`;
+CREATE TABLE `script_texts` (
+`id` int(11) unsigned NOT NULL auto_increment COMMENT 'Identifier',
+`sound` int(11) unsigned NOT NULL default '0',
+`type` int(11) unsigned NOT NULL default '0',
+`language` int(11) unsigned NOT NULL default '0',
+`text` varchar(255) NOT NULL default '',
+`comment` varchar(255) NOT NULL default '',
+PRIMARY KEY (`id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Script Texts';
View
15 sql/scriptdev2_structure.sql
@@ -72,14 +72,13 @@ PRIMARY KEY (`id`)
DROP TABLE IF EXISTS `script_texts`;
CREATE TABLE `script_texts` (
-`ScriptName` varchar(255) NOT NULL default '',
-`Id` int(11) unsigned NOT NULL default '0',
-`Sound` int(11) unsigned NOT NULL default '0',
-`Type` int(11) unsigned NOT NULL default '0',
-`Language` int(11) unsigned NOT NULL default '0',
-`Text` varchar(255) NOT NULL default '',
-`Comment` varchar(255) NOT NULL default '',
-PRIMARY KEY (`ScriptName`,`Id`)
+`id` int(11) unsigned NOT NULL auto_increment COMMENT 'Identifier',
+`sound` int(11) unsigned NOT NULL default '0',
+`type` int(11) unsigned NOT NULL default '0',
+`language` int(11) unsigned NOT NULL default '0',
+`text` varchar(255) NOT NULL default '',
+`comment` varchar(255) NOT NULL default '',
+PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Script Texts';
Please sign in to comment.
Something went wrong with that request. Please try again.