AssignWaypoints converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-08-20 13:58:36 -07:00
parent 87efd22394
commit 5fec840f06

View File

@ -869,55 +869,45 @@ void NPC::AssignWaypoints(int32 grid) {
return;
}
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
bool GridErr = false, WPErr = false;
Waypoints.clear();
roamer = false;
// Retrieve the wander and pause types for this grid
if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `type`,`type2` FROM `grid` WHERE `id`=%i AND `zoneid`=%i",grid,zone->GetZoneID()),errbuf, &result))
{
if((row = mysql_fetch_row(result)))
{
if(row[0] != 0)
wandertype = atoi(row[0]);
else
wandertype = 0;
if(row[1] != 0)
pausetype = atoi(row[1]);
else
pausetype = 0;
std::string query = StringFormat("SELECT `type`, `type2` FROM `grid` WHERE `id` = %i AND `zoneid` = %i", grid, zone->GetZoneID());
auto results = database.QueryDatabase(query);
if (!results.Success()) {
LogFile->write(EQEMuLog::Error, "MySQL Error while trying to assign grid %u to mob %s: %s", grid, name, results.ErrorMessage().c_str());
return;
}
else // No grid record found in this zone for the given ID
GridErr = true;
mysql_free_result(result);
}
else // DB query error!
{
GridErr = true;
LogFile->write(EQEMuLog::Error, "MySQL Error while trying to assign grid %u to mob %s: %s", grid, name, errbuf);
}
safe_delete_array(query);
if(!GridErr)
{
if (results.RowCount() == 0)
return;
auto row = results.begin();
wandertype = atoi(row[0]);
pausetype = atoi(row[1]);
this->CastToNPC()->SetGrid(grid); // Assign grid number
// Retrieve all waypoints for this grid
if(database.RunQuery(query,MakeAnyLenString(&query,"SELECT `x`,`y`,`z`,`pause`,`heading` FROM grid_entries WHERE `gridid`=%i AND `zoneid`=%i ORDER BY `number`",grid,zone->GetZoneID()),errbuf,&result))
{
roamer = true;
max_wp = -1; // Initialize it; will increment it for each waypoint successfully added to the list
query = StringFormat("SELECT `x`,`y`,`z`,`pause`,`heading` "
"FROM grid_entries WHERE `gridid` = %i AND `zoneid` = %i "
"ORDER BY `number`", grid, zone->GetZoneID());
results = database.QueryDatabase(query);
if (!results.Success()) {
LogFile->write(EQEMuLog::Error, "MySQL Error while trying to assign waypoints from grid %u to mob %s: %s", grid, name, results.ErrorMessage().c_str());
return;
}
while((row = mysql_fetch_row(result)))
{
if(row[0] != 0 && row[1] != 0 && row[2] != 0 && row[3] != 0)
roamer = true;
max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list
for (auto row = results.begin(); row != results.end(); ++row, ++max_wp)
{
wplist newwp;
newwp.index = ++max_wp;
newwp.index = max_wp;
newwp.x = atof(row[0]);
newwp.y = atof(row[1]);
newwp.z = atof(row[2]);
@ -940,26 +930,17 @@ void NPC::AssignWaypoints(int32 grid) {
newwp.heading = atof(row[4]);
Waypoints.push_back(newwp);
}
}
mysql_free_result(result);
}
else // DB query error!
{
WPErr = true;
LogFile->write(EQEMuLog::Error, "MySQL Error while trying to assign waypoints from grid %u to mob %s: %s", grid, name, errbuf);
}
safe_delete_array(query);
} // end if (!GridErr)
if(Waypoints.size() < 2) {
roamer = false;
} else if(!GridErr && !WPErr) {
}
UpdateWaypoint(0);
SetWaypointPause();
if (wandertype == 1 || wandertype == 2 || wandertype == 5)
CalculateNewWaypoint();
} else {
roamer = false;
}
}
void Mob::SendTo(float new_x, float new_y, float new_z) {