PopulateZoneSpawnList converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-08-24 13:00:39 -07:00
parent b36cc3ab08
commit 42a51eb373

View File

@ -354,34 +354,30 @@ void Spawn2::DeathReset(bool realdeath)
} }
bool ZoneDatabase::PopulateZoneSpawnList(uint32 zoneid, LinkedList<Spawn2*> &spawn2_list, int16 version, uint32 repopdelay) { bool ZoneDatabase::PopulateZoneSpawnList(uint32 zoneid, LinkedList<Spawn2*> &spawn2_list, int16 version, uint32 repopdelay) {
char errbuf[MYSQL_ERRMSG_SIZE];
char* query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
const char *zone_name = database.GetZoneName(zoneid); const char *zone_name = database.GetZoneName(zoneid);
std::string query = StringFormat("SELECT id, spawngroupID, x, y, z, heading, "
MakeAnyLenString(&query, "SELECT id, spawngroupID, x, y, z, heading, respawntime, variance, pathgrid, _condition, cond_value, enabled, animation FROM spawn2 WHERE zone='%s' AND version=%u", zone_name, version); "respawntime, variance, pathgrid, _condition, "
if (RunQuery(query, strlen(query), errbuf, &result)) "cond_value, enabled, animation FROM spawn2 "
{ "WHERE zone = '%s' AND version = %u",
safe_delete_array(query); zone_name, version);
while((row = mysql_fetch_row(result))) auto results = QueryDatabase(query);
{ if (!results.Success()) {
Spawn2* newSpawn = 0; LogFile->write(EQEMuLog::Error, "Error in PopulateZoneLists query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
bool perl_enabled = atoi(row[11]) == 1 ? true : false;
uint32 spawnLeft = (GetSpawnTimeLeft(atoi(row[0]), zone->GetInstanceID()) * 1000);
newSpawn = new Spawn2(atoi(row[0]), atoi(row[1]), atof(row[2]), atof(row[3]), atof(row[4]), atof(row[5]), atoi(row[6]), atoi(row[7]), spawnLeft, atoi(row[8]), atoi(row[9]), atoi(row[10]), perl_enabled, (EmuAppearance)atoi(row[12]));
spawn2_list.Insert( newSpawn );
}
mysql_free_result(result);
}
else
{
LogFile->write(EQEMuLog::Error, "Error in PopulateZoneLists query '%s': %s", query, errbuf);
safe_delete_array(query);
return false; return false;
} }
for (auto row = results.begin(); row != results.end(); ++row) {
Spawn2* newSpawn = 0;
bool perl_enabled = atoi(row[11]) == 1? true: false;
uint32 spawnLeft = (GetSpawnTimeLeft(atoi(row[0]), zone->GetInstanceID()) * 1000);
newSpawn = new Spawn2(atoi(row[0]), atoi(row[1]), atof(row[2]), atof(row[3]), atof(row[4]),
atof(row[5]), atoi(row[6]), atoi(row[7]), spawnLeft, atoi(row[8]),
atoi(row[9]), atoi(row[10]), perl_enabled, (EmuAppearance)atoi(row[12]));
spawn2_list.Insert(newSpawn);
}
return true; return true;
} }
@ -863,10 +859,10 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
SpawnEvent &cevent = *cur; SpawnEvent &cevent = *cur;
bool StrictCheck = false; bool StrictCheck = false;
if(cevent.strict && if(cevent.strict &&
cevent.next.hour == tod.hour && cevent.next.hour == tod.hour &&
cevent.next.day == tod.day && cevent.next.day == tod.day &&
cevent.next.month == tod.month && cevent.next.month == tod.month &&
cevent.next.year == tod.year) cevent.next.year == tod.year)
StrictCheck = true; StrictCheck = true;
@ -894,7 +890,7 @@ bool SpawnConditionManager::LoadSpawnConditions(const char* zone_name, uint32 in
//execute the event //execute the event
if(!cevent.strict || StrictCheck) if(!cevent.strict || StrictCheck)
ExecEvent(cevent, false); ExecEvent(cevent, false);
//add the period of the event to the trigger time //add the period of the event to the trigger time
EQTime::AddMinutes(cevent.period, &cevent.next); EQTime::AddMinutes(cevent.period, &cevent.next);
ran = true; ran = true;
@ -926,7 +922,7 @@ void SpawnConditionManager::FindNearestEvent() {
if(cevent.enabled) if(cevent.enabled)
{ {
//see if this event is before our last nearest //see if this event is before our last nearest
if(EQTime::IsTimeBefore(&next_event, &cevent.next)) if(EQTime::IsTimeBefore(&next_event, &cevent.next))
{ {
memcpy(&next_event, &cevent.next, sizeof(next_event)); memcpy(&next_event, &cevent.next, sizeof(next_event));
next_id = cevent.id; next_id = cevent.id;