Various Cleanups (game T-Z)

This commit is contained in:
Schmoozerd 2012-07-19 21:52:26 +02:00
parent 08fd085549
commit 6379a746d7
34 changed files with 2858 additions and 2852 deletions

View file

@ -32,20 +32,20 @@ bool WaypointBehavior::isEmpty()
if (emote || spell || model1 || model2)
return false;
for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i)
if(textid[i])
for (int i = 0; i < MAX_WAYPOINT_TEXT; ++i)
if (textid[i])
return false;
return true;
}
WaypointBehavior::WaypointBehavior(const WaypointBehavior &b)
WaypointBehavior::WaypointBehavior(const WaypointBehavior& b)
{
emote = b.emote;
spell = b.spell;
model1 = b.model1;
model2 = b.model2;
for(int i=0; i < MAX_WAYPOINT_TEXT; ++i)
for (int i=0; i < MAX_WAYPOINT_TEXT; ++i)
textid[i] = b.textid[i];
}
@ -59,18 +59,18 @@ void WaypointManager::Load()
std::set<uint32> movementScriptSet;
for(ScriptMapMap::const_iterator itr = sCreatureMovementScripts.second.begin(); itr != sCreatureMovementScripts.second.end(); ++itr)
for (ScriptMapMap::const_iterator itr = sCreatureMovementScripts.second.begin(); itr != sCreatureMovementScripts.second.end(); ++itr)
movementScriptSet.insert(itr->first);
// creature_movement
QueryResult *result = WorldDatabase.Query("SELECT id, COUNT(point) FROM creature_movement GROUP BY id");
QueryResult* result = WorldDatabase.Query("SELECT id, COUNT(point) FROM creature_movement GROUP BY id");
if (!result)
{
BarGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString( ">> Loaded 0 paths. DB table `creature_movement` is empty." );
sLog.outString(">> Loaded 0 paths. DB table `creature_movement` is empty.");
}
else
{
@ -80,7 +80,7 @@ void WaypointManager::Load()
do
{
bar.step();
Field *fields = result->Fetch();
Field* fields = result->Fetch();
uint32 id = fields[0].GetUInt32();
uint32 count = fields[1].GetUInt32();
@ -88,17 +88,17 @@ void WaypointManager::Load()
m_pathMap[id].resize(count);
total_nodes += count;
}
while(result->NextRow());
while (result->NextRow());
sLog.outString();
sLog.outString( ">> Paths loaded" );
sLog.outString(">> Paths loaded");
delete result;
// 0 1 2 3 4 5 6
result = WorldDatabase.Query("SELECT id, point, position_x, position_y, position_z, waittime, script_id,"
// 7 8 9 10 11 12 13 14 15 16
"textid1, textid2, textid3, textid4, textid5, emote, spell, orientation, model1, model2 FROM creature_movement");
// 7 8 9 10 11 12 13 14 15 16
"textid1, textid2, textid3, textid4, textid5, emote, spell, orientation, model1, model2 FROM creature_movement");
BarGoLink barRow((int)result->GetRowCount());
@ -108,7 +108,7 @@ void WaypointManager::Load()
do
{
barRow.step();
Field *fields = result->Fetch();
Field* fields = result->Fetch();
uint32 id = fields[0].GetUInt32();
uint32 point = fields[1].GetUInt32();
@ -123,12 +123,12 @@ void WaypointManager::Load()
if (cData->movementType != WAYPOINT_MOTION_TYPE)
creatureNoMoveType.insert(id);
WaypointPath &path = m_pathMap[id];
WaypointPath& path = m_pathMap[id];
// the cleanup queries make sure the following is true
MANGOS_ASSERT(point >= 1 && point <= path.size());
WaypointNode &node = path[point-1];
WaypointNode& node = path[point-1];
node.x = fields[2].GetFloat();
node.y = fields[3].GetFloat();
@ -140,13 +140,13 @@ void WaypointManager::Load()
// prevent using invalid coordinates
if (!MaNGOS::IsValidMapCoord(node.x, node.y, node.z, node.orientation))
{
QueryResult *result1 = WorldDatabase.PQuery("SELECT id, map FROM creature WHERE guid = '%u'", id);
QueryResult* result1 = WorldDatabase.PQuery("SELECT id, map FROM creature WHERE guid = '%u'", id);
if (result1)
sLog.outErrorDb("Creature (guidlow %d, entry %d) have invalid coordinates in his waypoint %d (X: %f, Y: %f).",
id, result1->Fetch()[0].GetUInt32(), point, node.x, node.y);
id, result1->Fetch()[0].GetUInt32(), point, node.x, node.y);
else
sLog.outErrorDb("Waypoint path %d, have invalid coordinates in his waypoint %d (X: %f, Y: %f).",
id, point, node.x, node.y);
id, point, node.x, node.y);
MaNGOS::NormalizeMapCoord(node.x);
MaNGOS::NormalizeMapCoord(node.y);
@ -179,7 +179,7 @@ void WaypointManager::Load()
be.emote = fields[12].GetUInt32();
be.spell = fields[13].GetUInt32();
for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i)
for (int i = 0; i < MAX_WAYPOINT_TEXT; ++i)
{
be.textid[i] = fields[7+i].GetUInt32();
@ -187,7 +187,7 @@ void WaypointManager::Load()
{
if (be.textid[i] < MIN_DB_SCRIPT_STRING_ID || be.textid[i] >= MAX_DB_SCRIPT_STRING_ID)
{
sLog.outErrorDb( "Table `db_script_string` not have string id %u", be.textid[i]);
sLog.outErrorDb("Table `db_script_string` not have string id %u", be.textid[i]);
continue;
}
}
@ -214,11 +214,11 @@ void WaypointManager::Load()
else
node.behavior = NULL;
}
while(result->NextRow());
while (result->NextRow());
if (!creatureNoMoveType.empty())
{
for(std::set<uint32>::const_iterator itr = creatureNoMoveType.begin(); itr != creatureNoMoveType.end(); ++itr)
for (std::set<uint32>::const_iterator itr = creatureNoMoveType.begin(); itr != creatureNoMoveType.end(); ++itr)
{
const CreatureData* cData = sObjectMgr.GetCreatureData(*itr);
const CreatureInfo* cInfo = ObjectMgr::GetCreatureTemplate(cData->id);
@ -231,9 +231,9 @@ void WaypointManager::Load()
}
sLog.outString();
sLog.outString( ">> Waypoints and behaviors loaded" );
sLog.outString(">> Waypoints and behaviors loaded");
sLog.outString();
sLog.outString( ">>> Loaded %u paths, %u nodes and %u behaviors", total_paths, total_nodes, total_behaviors);
sLog.outString(">>> Loaded %u paths, %u nodes and %u behaviors", total_paths, total_nodes, total_behaviors);
delete result;
}
@ -246,7 +246,7 @@ void WaypointManager::Load()
BarGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString( ">> Loaded 0 path templates. DB table `creature_movement_template` is empty." );
sLog.outString(">> Loaded 0 path templates. DB table `creature_movement_template` is empty.");
}
else
{
@ -258,7 +258,7 @@ void WaypointManager::Load()
do
{
barRow.step();
Field *fields = result->Fetch();
Field* fields = result->Fetch();
uint32 entry = fields[0].GetUInt32();
uint32 count = fields[1].GetUInt32();
@ -266,7 +266,7 @@ void WaypointManager::Load()
m_pathTemplateMap[entry].resize(count);
total_nodes += count;
}
while(result->NextRow());
while (result->NextRow());
delete result;
@ -275,15 +275,15 @@ void WaypointManager::Load()
// 0 1 2 3 4 5 6
result = WorldDatabase.Query("SELECT entry, point, position_x, position_y, position_z, waittime, script_id,"
// 7 8 9 10 11 12 13 14 15 16
"textid1, textid2, textid3, textid4, textid5, emote, spell, orientation, model1, model2 FROM creature_movement_template");
// 7 8 9 10 11 12 13 14 15 16
"textid1, textid2, textid3, textid4, textid5, emote, spell, orientation, model1, model2 FROM creature_movement_template");
BarGoLink bar(result->GetRowCount());
do
{
bar.step();
Field *fields = result->Fetch();
Field* fields = result->Fetch();
uint32 entry = fields[0].GetUInt32();
uint32 point = fields[1].GetUInt32();
@ -296,12 +296,12 @@ void WaypointManager::Load()
continue;
}
WaypointPath &path = m_pathTemplateMap[entry];
WaypointPath& path = m_pathTemplateMap[entry];
// the cleanup queries make sure the following is true
MANGOS_ASSERT(point >= 1 && point <= path.size());
WaypointNode &node = path[point-1];
WaypointNode& node = path[point-1];
node.x = fields[2].GetFloat();
node.y = fields[3].GetFloat();
@ -314,13 +314,13 @@ void WaypointManager::Load()
if (!MaNGOS::IsValidMapCoord(node.x, node.y, node.z, node.orientation))
{
sLog.outErrorDb("Table creature_movement_template for entry %u (point %u) are using invalid coordinates position_x: %f, position_y: %f)",
entry, point, node.x, node.y);
entry, point, node.x, node.y);
MaNGOS::NormalizeMapCoord(node.x);
MaNGOS::NormalizeMapCoord(node.y);
sLog.outErrorDb("Table creature_movement_template for entry %u (point %u) are auto corrected to normalized position_x=%f, position_y=%f",
entry, point, node.x, node.y);
entry, point, node.x, node.y);
WorldDatabase.PExecute("UPDATE creature_movement_template SET position_x = '%f', position_y = '%f' WHERE entry = %u AND point = %u", node.x, node.y, entry, point);
}
@ -342,7 +342,7 @@ void WaypointManager::Load()
be.emote = fields[12].GetUInt32();
be.spell = fields[13].GetUInt32();
for(int i = 0; i < MAX_WAYPOINT_TEXT; ++i)
for (int i = 0; i < MAX_WAYPOINT_TEXT; ++i)
{
be.textid[i] = fields[7+i].GetUInt32();
@ -350,7 +350,7 @@ void WaypointManager::Load()
{
if (be.textid[i] < MIN_DB_SCRIPT_STRING_ID || be.textid[i] >= MAX_DB_SCRIPT_STRING_ID)
{
sLog.outErrorDb( "Table `db_script_string` not have string id %u", be.textid[i]);
sLog.outErrorDb("Table `db_script_string` not have string id %u", be.textid[i]);
continue;
}
}
@ -377,19 +377,19 @@ void WaypointManager::Load()
else
node.behavior = NULL;
}
while(result->NextRow());
while (result->NextRow());
delete result;
sLog.outString();
sLog.outString( ">> Waypoint templates loaded" );
sLog.outString(">> Waypoint templates loaded");
sLog.outString();
sLog.outString( ">>> Loaded %u path templates with %u nodes and %u behaviors", total_paths, total_nodes, total_behaviors);
sLog.outString(">>> Loaded %u path templates with %u nodes and %u behaviors", total_paths, total_nodes, total_behaviors);
}
if (!movementScriptSet.empty())
{
for(std::set<uint32>::const_iterator itr = movementScriptSet.begin(); itr != movementScriptSet.end(); ++itr)
for (std::set<uint32>::const_iterator itr = movementScriptSet.begin(); itr != movementScriptSet.end(); ++itr)
sLog.outErrorDb("Table `creature_movement_scripts` contain unused script, id %u.", *itr);
}
}
@ -397,7 +397,7 @@ void WaypointManager::Load()
void WaypointManager::Cleanup()
{
// check if points need to be renumbered and do it
if (QueryResult *result = WorldDatabase.Query("SELECT 1 from creature_movement As T WHERE point <> (SELECT COUNT(*) FROM creature_movement WHERE id = T.id AND point <= T.point) LIMIT 1"))
if (QueryResult* result = WorldDatabase.Query("SELECT 1 from creature_movement As T WHERE point <> (SELECT COUNT(*) FROM creature_movement WHERE id = T.id AND point <= T.point) LIMIT 1"))
{
delete result;
WorldDatabase.DirectExecute("CREATE TEMPORARY TABLE temp LIKE creature_movement");
@ -412,7 +412,7 @@ void WaypointManager::Cleanup()
MANGOS_ASSERT(!(result = WorldDatabase.Query("SELECT 1 from creature_movement As T WHERE point <> (SELECT COUNT(*) FROM creature_movement WHERE id = T.id AND point <= T.point) LIMIT 1")));
}
if (QueryResult *result = WorldDatabase.Query("SELECT 1 from creature_movement_template As T WHERE point <> (SELECT COUNT(*) FROM creature_movement_template WHERE entry = T.entry AND point <= T.point) LIMIT 1"))
if (QueryResult* result = WorldDatabase.Query("SELECT 1 from creature_movement_template As T WHERE point <> (SELECT COUNT(*) FROM creature_movement_template WHERE entry = T.entry AND point <= T.point) LIMIT 1"))
{
delete result;
WorldDatabase.DirectExecute("CREATE TEMPORARY TABLE temp LIKE creature_movement_template");
@ -430,15 +430,15 @@ void WaypointManager::Cleanup()
void WaypointManager::Unload()
{
for(WaypointPathMap::iterator itr = m_pathMap.begin(); itr != m_pathMap.end(); ++itr)
for (WaypointPathMap::iterator itr = m_pathMap.begin(); itr != m_pathMap.end(); ++itr)
_clearPath(itr->second);
m_pathMap.clear();
}
void WaypointManager::_clearPath(WaypointPath &path)
void WaypointManager::_clearPath(WaypointPath& path)
{
for(WaypointPath::const_iterator itr = path.begin(); itr != path.end(); ++itr)
if(itr->behavior)
for (WaypointPath::const_iterator itr = path.begin(); itr != path.end(); ++itr)
if (itr->behavior)
delete itr->behavior;
path.clear();
}
@ -452,7 +452,7 @@ void WaypointManager::AddLastNode(uint32 id, float x, float y, float z, float o,
/// - Insert after a certain point
void WaypointManager::AddAfterNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid)
{
for(uint32 i = GetLastPoint(id, 0); i > point; i--)
for (uint32 i = GetLastPoint(id, 0); i > point; i--)
WorldDatabase.PExecuteLog("UPDATE creature_movement SET point=point+1 WHERE id=%u AND point=%u", id, i);
_addNode(id, point + 1, x, y, z, o, delay, wpGuid);
@ -461,12 +461,12 @@ void WaypointManager::AddAfterNode(uint32 id, uint32 point, float x, float y, fl
/// - Insert without checking for collision
void WaypointManager::_addNode(uint32 id, uint32 point, float x, float y, float z, float o, uint32 delay, uint32 wpGuid)
{
if(point == 0) return; // counted from 1 in the DB
if (point == 0) return; // counted from 1 in the DB
WorldDatabase.PExecuteLog("INSERT INTO creature_movement (id,point,position_x,position_y,position_z,orientation,wpguid,waittime) "
"VALUES (%u,%u, %f,%f,%f,%f, %u,%u)",
id, point, x, y, z, o, wpGuid, delay);
"VALUES (%u,%u, %f,%f,%f,%f, %u,%u)",
id, point, x, y, z, o, wpGuid, delay);
WaypointPathMap::iterator itr = m_pathMap.find(id);
if(itr == m_pathMap.end())
if (itr == m_pathMap.end())
itr = m_pathMap.insert(WaypointPathMap::value_type(id, WaypointPath())).first;
itr->second.insert(itr->second.begin() + (point - 1), WaypointNode(x, y, z, o, delay, 0, NULL));
}
@ -481,18 +481,18 @@ uint32 WaypointManager::GetLastPoint(uint32 id, uint32 default_notfound)
delete result;
}*/
WaypointPathMap::const_iterator itr = m_pathMap.find(id);
if(itr != m_pathMap.end() && itr->second.size() != 0)
if (itr != m_pathMap.end() && itr->second.size() != 0)
point = itr->second.size();
return point;
}
void WaypointManager::DeleteNode(uint32 id, uint32 point)
{
if(point == 0) return; // counted from 1 in the DB
if (point == 0) return; // counted from 1 in the DB
WorldDatabase.PExecuteLog("DELETE FROM creature_movement WHERE id=%u AND point=%u", id, point);
WorldDatabase.PExecuteLog("UPDATE creature_movement SET point=point-1 WHERE id=%u AND point>%u", id, point);
WaypointPathMap::iterator itr = m_pathMap.find(id);
if(itr != m_pathMap.end() && point <= itr->second.size())
if (itr != m_pathMap.end() && point <= itr->second.size())
itr->second.erase(itr->second.begin() + (point-1));
}
@ -500,7 +500,7 @@ void WaypointManager::DeletePath(uint32 id)
{
WorldDatabase.PExecuteLog("DELETE FROM creature_movement WHERE id=%u", id);
WaypointPathMap::iterator itr = m_pathMap.find(id);
if(itr != m_pathMap.end())
if (itr != m_pathMap.end())
_clearPath(itr->second);
// the path is not removed from the map, just cleared
// WMGs have pointers to the path, so deleting them would crash
@ -510,10 +510,10 @@ void WaypointManager::DeletePath(uint32 id)
void WaypointManager::SetNodePosition(uint32 id, uint32 point, float x, float y, float z)
{
if(point == 0) return; // counted from 1 in the DB
if (point == 0) return; // counted from 1 in the DB
WorldDatabase.PExecuteLog("UPDATE creature_movement SET position_x=%f, position_y=%f, position_z=%f WHERE id=%u AND point=%u", x, y, z, id, point);
WaypointPathMap::iterator itr = m_pathMap.find(id);
if(itr != m_pathMap.end() && point <= itr->second.size())
if (itr != m_pathMap.end() && point <= itr->second.size())
{
itr->second[point-1].x = x;
itr->second[point-1].y = y;
@ -521,14 +521,14 @@ void WaypointManager::SetNodePosition(uint32 id, uint32 point, float x, float y,
}
}
void WaypointManager::SetNodeText(uint32 id, uint32 point, const char *text_field, const char *text)
void WaypointManager::SetNodeText(uint32 id, uint32 point, const char* text_field, const char* text)
{
if(point == 0) return; // counted from 1 in the DB
if(!text_field) return;
if (point == 0) return; // counted from 1 in the DB
if (!text_field) return;
std::string field = text_field;
WorldDatabase.escape_string(field);
if(!text)
if (!text)
{
WorldDatabase.PExecuteLog("UPDATE creature_movement SET %s=NULL WHERE id='%u' AND point='%u'", field.c_str(), id, point);
}
@ -540,27 +540,27 @@ void WaypointManager::SetNodeText(uint32 id, uint32 point, const char *text_fiel
}
WaypointPathMap::iterator itr = m_pathMap.find(id);
if(itr != m_pathMap.end() && point <= itr->second.size())
if (itr != m_pathMap.end() && point <= itr->second.size())
{
WaypointNode &node = itr->second[point-1];
if(!node.behavior) node.behavior = new WaypointBehavior();
WaypointNode& node = itr->second[point-1];
if (!node.behavior) node.behavior = new WaypointBehavior();
// if(field == "text1") node.behavior->text[0] = text ? text : "";
// if(field == "text2") node.behavior->text[1] = text ? text : "";
// if(field == "text3") node.behavior->text[2] = text ? text : "";
// if(field == "text4") node.behavior->text[3] = text ? text : "";
// if(field == "text5") node.behavior->text[4] = text ? text : "";
if(field == "emote") node.behavior->emote = text ? atoi(text) : 0;
if(field == "spell") node.behavior->spell = text ? atoi(text) : 0;
if(field == "model1") node.behavior->model1 = text ? atoi(text) : 0;
if(field == "model2") node.behavior->model2 = text ? atoi(text) : 0;
if (field == "emote") node.behavior->emote = text ? atoi(text) : 0;
if (field == "spell") node.behavior->spell = text ? atoi(text) : 0;
if (field == "model1") node.behavior->model1 = text ? atoi(text) : 0;
if (field == "model2") node.behavior->model2 = text ? atoi(text) : 0;
}
}
void WaypointManager::CheckTextsExistance(std::set<int32>& ids)
{
WaypointPathMap::const_iterator pmItr = m_pathMap.begin();
for ( ; pmItr != m_pathMap.end(); ++pmItr)
for (; pmItr != m_pathMap.end(); ++pmItr)
{
for (size_t i = 0; i < pmItr->second.size(); ++i)
{
@ -604,7 +604,7 @@ void WaypointManager::CheckTextsExistance(std::set<int32>& ids)
}
WaypointPathTemplateMap::const_iterator wptItr = m_pathTemplateMap.begin();
for ( ; wptItr != m_pathTemplateMap.end(); ++wptItr)
for (; wptItr != m_pathTemplateMap.end(); ++wptItr)
{
for (size_t i = 0; i < wptItr->second.size(); ++i)
{