aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Globals/ObjectMgr.cpp
diff options
context:
space:
mode:
authorazazel <none@none>2010-09-22 18:13:57 +0600
committerazazel <none@none>2010-09-22 18:13:57 +0600
commiteae0e5c822d979694f5d686269391c4643bc9fcf (patch)
tree45fa2324df331c0a43bd2a16efe74591dfeef196 /src/server/game/Globals/ObjectMgr.cpp
parent562a8c272d2402a870a0f7a51b0742cc1e4d9192 (diff)
Scripts/DB_Scripts: massive cleanup of SCRIPT_COMMAND_* related staff
* add union into ScriptInfo structure (thanks NoFantasy for the idea); * move scripts methods from Map.cpp to new file MapScripts.cpp; * remove magic numbers and introduce eScriptFlags enumeration. It's just a beginning and more changes to come. Stay tuned! --HG-- branch : trunk
Diffstat (limited to 'src/server/game/Globals/ObjectMgr.cpp')
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp222
1 files changed, 113 insertions, 109 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index c67c3e214e4..4d2eac5b898 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -4726,41 +4726,41 @@ void ObjectMgr::LoadScripts(ScriptsType type)
Field *fields = result->Fetch();
ScriptInfo tmp;
- tmp.id = fields[0].GetUInt32();
- if (isSpellScriptTable)
- tmp.id |= fields[10].GetUInt8() << 24;
- tmp.delay = fields[1].GetUInt32();
- tmp.command = ScriptCommands(fields[2].GetUInt32());
- tmp.datalong = fields[3].GetUInt32();
- tmp.datalong2 = fields[4].GetUInt32();
- tmp.dataint = fields[5].GetInt32();
- tmp.x = fields[6].GetFloat();
- tmp.y = fields[7].GetFloat();
- tmp.z = fields[8].GetFloat();
- tmp.o = fields[9].GetFloat();
tmp.type = type;
+ tmp.id = fields[0].GetUInt32();
+ if (isSpellScriptTable)
+ tmp.id |= fields[10].GetUInt8() << 24;
+ tmp.delay = fields[1].GetUInt32();
+ tmp.command = ScriptCommands(fields[2].GetUInt32());
+ tmp.Raw.nData[0] = fields[3].GetUInt32();
+ tmp.Raw.nData[1] = fields[4].GetUInt32();
+ tmp.Raw.nData[2] = fields[5].GetInt32();
+ tmp.Raw.fData[0] = fields[6].GetFloat();
+ tmp.Raw.fData[1] = fields[7].GetFloat();
+ tmp.Raw.fData[2] = fields[8].GetFloat();
+ tmp.Raw.fData[3] = fields[9].GetFloat();
// generic command args check
switch (tmp.command)
{
case SCRIPT_COMMAND_TALK:
{
- if (tmp.datalong > CHAT_TYPE_WHISPER && tmp.datalong != CHAT_MSG_RAID_BOSS_WHISPER)
+ if (tmp.Talk.ChatType > CHAT_TYPE_WHISPER && tmp.Talk.ChatType != CHAT_MSG_RAID_BOSS_WHISPER)
{
sLog.outErrorDb("Table `%s` has invalid talk type (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ tableName.c_str(), tmp.Talk.ChatType, tmp.id);
continue;
}
- if (tmp.dataint == 0)
+ if (!tmp.Talk.TextID)
{
sLog.outErrorDb("Table `%s` has invalid talk text id (dataint = %i) in SCRIPT_COMMAND_TALK for script id %u",
- tableName.c_str(),tmp.dataint,tmp.id);
+ tableName.c_str(), tmp.Talk.TextID, tmp.id);
continue;
}
- if (tmp.dataint < MIN_DB_SCRIPT_STRING_ID || tmp.dataint >= MAX_DB_SCRIPT_STRING_ID)
+ if (tmp.Talk.TextID < MIN_DB_SCRIPT_STRING_ID || tmp.Talk.TextID >= MAX_DB_SCRIPT_STRING_ID)
{
sLog.outErrorDb("Table `%s` has out of range text id (dataint = %i expected %u-%u) in SCRIPT_COMMAND_TALK for script id %u",
- tableName.c_str(),tmp.dataint,MIN_DB_SCRIPT_STRING_ID,MAX_DB_SCRIPT_STRING_ID,tmp.id);
+ tableName.c_str(), tmp.Talk.TextID, MIN_DB_SCRIPT_STRING_ID, MAX_DB_SCRIPT_STRING_ID, tmp.id);
continue;
}
@@ -4769,10 +4769,10 @@ void ObjectMgr::LoadScripts(ScriptsType type)
case SCRIPT_COMMAND_EMOTE:
{
- if (!sEmotesStore.LookupEntry(tmp.datalong))
+ if (!sEmotesStore.LookupEntry(tmp.Emote.EmoteID))
{
sLog.outErrorDb("Table `%s` has invalid emote id (datalong = %u) in SCRIPT_COMMAND_EMOTE for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ tableName.c_str(), tmp.Emote.EmoteID, tmp.id);
continue;
}
break;
@@ -4780,46 +4780,73 @@ void ObjectMgr::LoadScripts(ScriptsType type)
case SCRIPT_COMMAND_TELEPORT_TO:
{
- if (!sMapStore.LookupEntry(tmp.datalong))
+ if (!sMapStore.LookupEntry(tmp.TeleportTo.MapID))
{
sLog.outErrorDb("Table `%s` has invalid map (Id: %u) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ tableName.c_str(), tmp.TeleportTo.MapID, tmp.id);
continue;
}
- if (!Trinity::IsValidMapCoord(tmp.x,tmp.y,tmp.z,tmp.o))
+ if (!Trinity::IsValidMapCoord(tmp.TeleportTo.DestX, tmp.TeleportTo.DestY, tmp.TeleportTo.DestZ, tmp.TeleportTo.Orientation))
{
- sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",
- tableName.c_str(),tmp.x,tmp.y,tmp.id);
+ sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f Z: %f O: %f) in SCRIPT_COMMAND_TELEPORT_TO for script id %u",
+ tableName.c_str(), tmp.TeleportTo.DestX, tmp.TeleportTo.DestY, tmp.TeleportTo.DestZ, tmp.TeleportTo.Orientation, tmp.id);
continue;
}
break;
}
- case SCRIPT_COMMAND_KILL_CREDIT:
+ case SCRIPT_COMMAND_QUEST_EXPLORED:
{
- if (!GetCreatureTemplate(tmp.datalong))
+ Quest const* quest = GetQuestTemplate(tmp.QuestExplored.QuestID);
+ if (!quest)
{
- sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_KILL_CREDIT for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ sLog.outErrorDb("Table `%s` has invalid quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
+ tableName.c_str(), tmp.QuestExplored.QuestID, tmp.id);
continue;
}
- break;
- }
- case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE:
- {
- if (!Trinity::IsValidMapCoord(tmp.x,tmp.y,tmp.z,tmp.o))
+ if (!quest->HasFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT))
{
- sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",
- tableName.c_str(),tmp.x,tmp.y,tmp.id);
+ sLog.outErrorDb("Table `%s` has quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, but quest not have flag QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT in quest flags. Script command or quest flags wrong. Quest modified to require objective.",
+ tableName.c_str(), tmp.QuestExplored.QuestID, tmp.id);
+
+ // this will prevent quest completing without objective
+ const_cast<Quest*>(quest)->SetFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT);
+
+ // continue; - quest objective requirement set and command can be allowed
+ }
+
+ if (float(tmp.QuestExplored.Distance) > DEFAULT_VISIBILITY_DISTANCE)
+ {
+ sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
+ tableName.c_str(), tmp.QuestExplored.Distance, tmp.id);
continue;
}
- if (!GetCreatureTemplate(tmp.datalong))
+ if (tmp.QuestExplored.Distance && float(tmp.QuestExplored.Distance) > DEFAULT_VISIBILITY_DISTANCE)
{
- sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, max distance is %f or 0 for disable distance check",
+ tableName.c_str(), tmp.QuestExplored.Distance, tmp.id, DEFAULT_VISIBILITY_DISTANCE);
+ continue;
+ }
+
+ if (tmp.QuestExplored.Distance && float(tmp.QuestExplored.Distance) < INTERACTION_DISTANCE)
+ {
+ sLog.outErrorDb("Table `%s` has too small distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, min distance is %f or 0 for disable distance check",
+ tableName.c_str(), tmp.QuestExplored.Distance, tmp.id, INTERACTION_DISTANCE);
+ continue;
+ }
+
+ break;
+ }
+
+ case SCRIPT_COMMAND_KILL_CREDIT:
+ {
+ if (!GetCreatureTemplate(tmp.KillCredit.CreatureEntry))
+ {
+ sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_KILL_CREDIT for script id %u",
+ tableName.c_str(), tmp.KillCredit.CreatureEntry, tmp.id);
continue;
}
break;
@@ -4827,11 +4854,11 @@ void ObjectMgr::LoadScripts(ScriptsType type)
case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT:
{
- GameObjectData const* data = GetGOData(tmp.datalong);
+ GameObjectData const* data = GetGOData(tmp.RespawnGameobject.GOGuid);
if (!data)
{
sLog.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ tableName.c_str(), tmp.RespawnGameobject.GOGuid, tmp.id);
continue;
}
@@ -4839,7 +4866,7 @@ void ObjectMgr::LoadScripts(ScriptsType type)
if (!info)
{
sLog.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",
- tableName.c_str(),tmp.datalong,data->id,tmp.id);
+ tableName.c_str(), tmp.RespawnGameobject.GOGuid, data->id, tmp.id);
continue;
}
@@ -4850,77 +4877,53 @@ void ObjectMgr::LoadScripts(ScriptsType type)
info->type == GAMEOBJECT_TYPE_TRAP)
{
sLog.outErrorDb("Table `%s` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u",
- tableName.c_str(),info->id,tmp.id);
+ tableName.c_str(), info->id, tmp.id);
continue;
}
break;
}
- case SCRIPT_COMMAND_OPEN_DOOR:
- case SCRIPT_COMMAND_CLOSE_DOOR:
- {
- GameObjectData const* data = GetGOData(tmp.datalong);
- if (!data)
- {
- sLog.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in %s for script id %u",
- tableName.c_str(),tmp.datalong,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id);
- continue;
- }
- GameObjectInfo const* info = GetGameObjectInfo(data->id);
- if (!info)
+ case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE:
+ {
+ if (!Trinity::IsValidMapCoord(tmp.TempSummonCreature.PosX, tmp.TempSummonCreature.PosY, tmp.TempSummonCreature.PosZ, tmp.TempSummonCreature.Orientation))
{
- sLog.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in %s for script id %u",
- tableName.c_str(),tmp.datalong,data->id,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id);
+ sLog.outErrorDb("Table `%s` has invalid coordinates (X: %f Y: %f Z: %f O: %f) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",
+ tableName.c_str(), tmp.TempSummonCreature.PosX, tmp.TempSummonCreature.PosY, tmp.TempSummonCreature.PosZ, tmp.TempSummonCreature.Orientation, tmp.id);
continue;
}
- if (info->type != GAMEOBJECT_TYPE_DOOR)
+ if (!GetCreatureTemplate(tmp.TempSummonCreature.CreatureEntry))
{
- sLog.outErrorDb("Table `%s` has gameobject type (%u) non supported by command %s for script id %u",tableName.c_str(),info->id,(tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"),tmp.id);
+ sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_TEMP_SUMMON_CREATURE for script id %u",
+ tableName.c_str(), tmp.TempSummonCreature.CreatureEntry, tmp.id);
continue;
}
-
break;
}
- case SCRIPT_COMMAND_QUEST_EXPLORED:
- {
- Quest const* quest = GetQuestTemplate(tmp.datalong);
- if (!quest)
- {
- sLog.outErrorDb("Table `%s` has invalid quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
- continue;
- }
-
- if (!quest->HasFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT))
- {
- sLog.outErrorDb("Table `%s` has quest (ID: %u) in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, but quest not have flag QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT in quest flags. Script command or quest flags wrong. Quest modified to require objective.",
- tableName.c_str(),tmp.datalong,tmp.id);
-
- // this will prevent quest completing without objective
- const_cast<Quest*>(quest)->SetFlag(QUEST_TRINITY_FLAGS_EXPLORATION_OR_EVENT);
- // continue; - quest objective requirement set and command can be allowed
- }
-
- if (float(tmp.datalong2) > DEFAULT_VISIBILITY_DISTANCE)
+ case SCRIPT_COMMAND_OPEN_DOOR:
+ case SCRIPT_COMMAND_CLOSE_DOOR:
+ {
+ GameObjectData const* data = GetGOData(tmp.ToggleDoor.GOGuid);
+ if (!data)
{
- sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u",
- tableName.c_str(),tmp.datalong2,tmp.id);
+ sLog.outErrorDb("Table `%s` has invalid gameobject (GUID: %u) in %s for script id %u",
+ tableName.c_str(), tmp.ToggleDoor.GOGuid, GetScriptCommandName(tmp.command).c_str(), tmp.id);
continue;
}
- if (tmp.datalong2 && float(tmp.datalong2) > DEFAULT_VISIBILITY_DISTANCE)
+ GameObjectInfo const* info = GetGameObjectInfo(data->id);
+ if (!info)
{
- sLog.outErrorDb("Table `%s` has too large distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, max distance is %f or 0 for disable distance check",
- tableName.c_str(),tmp.datalong2,tmp.id,DEFAULT_VISIBILITY_DISTANCE);
+ sLog.outErrorDb("Table `%s` has gameobject with invalid entry (GUID: %u Entry: %u) in %s for script id %u",
+ tableName.c_str(), tmp.ToggleDoor.GOGuid, data->id, GetScriptCommandName(tmp.command).c_str(), tmp.id);
continue;
}
- if (tmp.datalong2 && float(tmp.datalong2) < INTERACTION_DISTANCE)
+ if (info->type != GAMEOBJECT_TYPE_DOOR)
{
- sLog.outErrorDb("Table `%s` has too small distance (%u) for exploring objective complete in `datalong2` in SCRIPT_COMMAND_QUEST_EXPLORED in `datalong` for script id %u, min distance is %f or 0 for disable distance check",
- tableName.c_str(),tmp.datalong2,tmp.id,INTERACTION_DISTANCE);
+ sLog.outErrorDb("Table `%s` has gameobject type (%u) non supported by command %s for script id %u",
+ tableName.c_str(), info->id, GetScriptCommandName(tmp.command).c_str(), tmp.id);
continue;
}
@@ -4929,44 +4932,45 @@ void ObjectMgr::LoadScripts(ScriptsType type)
case SCRIPT_COMMAND_REMOVE_AURA:
{
- if (!sSpellStore.LookupEntry(tmp.datalong))
+ if (!sSpellStore.LookupEntry(tmp.RemoveAura.SpellID))
{
sLog.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ tableName.c_str(), tmp.RemoveAura.SpellID, tmp.id);
continue;
}
- if (tmp.datalong2 & ~0x1) // 1 bits (0,1)
+ if (tmp.RemoveAura.Flags & ~0x1) // 1 bits (0,1)
{
sLog.outErrorDb("Table `%s` using unknown flags in datalong2 (%u) in SCRIPT_COMMAND_REMOVE_AURA for script id %u",
- tableName.c_str(),tmp.datalong2,tmp.id);
+ tableName.c_str(), tmp.RemoveAura.Flags, tmp.id);
continue;
}
break;
}
+
case SCRIPT_COMMAND_CAST_SPELL:
{
- if (!sSpellStore.LookupEntry(tmp.datalong))
+ if (!sSpellStore.LookupEntry(tmp.CastSpell.SpellID))
{
sLog.outErrorDb("Table `%s` using non-existent spell (id: %u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
- tableName.c_str(),tmp.datalong,tmp.id);
+ tableName.c_str(), tmp.CastSpell.SpellID, tmp.id);
continue;
}
- if (tmp.datalong2 > 4) // targeting type
+ if (tmp.CastSpell.Flags > 4) // targeting type
{
sLog.outErrorDb("Table `%s` using unknown target in datalong2 (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
- tableName.c_str(),tmp.datalong2,tmp.id);
+ tableName.c_str(), tmp.CastSpell.Flags, tmp.id);
continue;
}
- if (tmp.datalong2 != 4 && tmp.dataint & ~0x1) // 1 bit (0,1)
+ if (tmp.CastSpell.Flags != 4 && tmp.CastSpell.CreatureEntry & ~0x1) // 1 bit (0,1)
{
sLog.outErrorDb("Table `%s` using unknown flags in dataint (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
- tableName.c_str(),tmp.dataint,tmp.id);
+ tableName.c_str(), tmp.CastSpell.CreatureEntry, tmp.id);
continue;
}
- else if (tmp.datalong2 == 4 && !GetCreatureTemplate(tmp.dataint))
+ else if (tmp.CastSpell.Flags == 4 && !GetCreatureTemplate(tmp.CastSpell.CreatureEntry))
{
sLog.outErrorDb("Table `%s` using invalid creature entry in dataint (%u) in SCRIPT_COMMAND_CAST_SPELL for script id %u",
- tableName.c_str(),tmp.dataint,tmp.id);
+ tableName.c_str(), tmp.CastSpell.CreatureEntry, tmp.id);
continue;
}
break;
@@ -4974,16 +4978,16 @@ void ObjectMgr::LoadScripts(ScriptsType type)
case SCRIPT_COMMAND_CREATE_ITEM:
{
- if (!GetItemPrototype(tmp.datalong))
+ if (!GetItemPrototype(tmp.CreateItem.ItemEntry))
{
sLog.outErrorDb("Table `%s` has nonexistent item (entry: %u) in SCRIPT_COMMAND_CREATE_ITEM for script id %u",
- tableName.c_str(), tmp.datalong, tmp.id);
+ tableName.c_str(), tmp.CreateItem.ItemEntry, tmp.id);
continue;
}
- if (!tmp.datalong2)
+ if (!tmp.CreateItem.Amount)
{
sLog.outErrorDb("Table `%s` SCRIPT_COMMAND_CREATE_ITEM but amount is %u for script id %u",
- tableName.c_str(), tmp.datalong2, tmp.id);
+ tableName.c_str(), tmp.CreateItem.Amount, tmp.id);
continue;
}
break;
@@ -8939,11 +8943,11 @@ void ObjectMgr::CheckScripts(ScriptsType type, std::set<int32>& ids)
{
case SCRIPT_COMMAND_TALK:
{
- if (!GetTrinityStringLocale (itrM->second.dataint))
- sLog.outErrorDb("Table `db_script_string` not has string id %u used db script (ID: %u)", itrM->second.dataint, itrMM->first);
+ if (!GetTrinityStringLocale (itrM->second.Talk.TextID))
+ sLog.outErrorDb("Table `db_script_string` not has string id %u used db script (ID: %u)", itrM->second.Talk.TextID, itrMM->first);
- if (ids.find(itrM->second.dataint) != ids.end())
- ids.erase(itrM->second.dataint);
+ if (ids.find(itrM->second.Talk.TextID) != ids.end())
+ ids.erase(itrM->second.Talk.TextID);
}
default:
break;