diff --git a/zone/tasks.cpp b/zone/tasks.cpp index 0ba1a72fe..a0d21f61f 100644 --- a/zone/tasks.cpp +++ b/zone/tasks.cpp @@ -3099,7 +3099,6 @@ void ClientTaskState::ProcessTaskProximities(Client *c, float X, float Y, float TaskGoalListManager::TaskGoalListManager() { - TaskGoalLists = nullptr; NumberOfLists = 0; } @@ -3111,48 +3110,45 @@ TaskGoalListManager::~TaskGoalListManager() { safe_delete_array(TaskGoalLists[i].GoalItemEntries); } - safe_delete_array(TaskGoalLists); } -bool TaskGoalListManager::LoadLists() { +bool TaskGoalListManager::LoadLists() +{ Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] TaskGoalListManager::LoadLists Called"); - for(int i=0; i< NumberOfLists; i++) + for (int i = 0; i < NumberOfLists; i++) safe_delete_array(TaskGoalLists[i].GoalItemEntries); - safe_delete_array(TaskGoalLists); + TaskGoalLists.clear(); - const char *ERR_MYSQLERROR = "Error in TaskGoalListManager::LoadLists: %s %s"; + const char *ERR_MYSQLERROR = "Error in TaskGoalListManager::LoadLists: %s %s"; NumberOfLists = 0; - std::string query = "SELECT `listid`, COUNT(`entry`) " - "FROM `goallists` GROUP by `listid` " - "ORDER BY `listid`"; - auto results = database.QueryDatabase(query); - if (!results.Success()) { + std::string query = "SELECT `listid`, COUNT(`entry`) " + "FROM `goallists` GROUP by `listid` " + "ORDER BY `listid`"; + auto results = database.QueryDatabase(query); + if (!results.Success()) { return false; - } + } - NumberOfLists = results.RowCount(); - Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] Database returned a count of %i lists", NumberOfLists); + NumberOfLists = results.RowCount(); + Log(Logs::General, Logs::Tasks, "[GLOBALLOAD] Database returned a count of %i lists", NumberOfLists); - TaskGoalLists = new TaskGoalList_Struct[NumberOfLists]; + TaskGoalLists.reserve(NumberOfLists); - int listIndex = 0; + int listIndex = 0; - for(auto row = results.begin(); row != results.end(); ++row) { - int listID = atoi(row[0]); - int listSize = atoi(row[1]); + for (auto row = results.begin(); row != results.end(); ++row) { + int listID = atoi(row[0]); + int listSize = atoi(row[1]); + TaskGoalLists.push_back({listID, listSize, 0, 0, nullptr}); - TaskGoalLists[listIndex].ListID = listID; - TaskGoalLists[listIndex].Size = listSize; - TaskGoalLists[listIndex].Min = 0; - TaskGoalLists[listIndex].Max = 0; - TaskGoalLists[listIndex].GoalItemEntries = new int[listSize]; + TaskGoalLists[listIndex].GoalItemEntries = new int[listSize]; - listIndex++; - } + listIndex++; + } for(int listIndex = 0; listIndex < NumberOfLists; listIndex++) { diff --git a/zone/tasks.h b/zone/tasks.h index b0b7956ab..1ab7cd0f9 100644 --- a/zone/tasks.h +++ b/zone/tasks.h @@ -75,7 +75,7 @@ public: private: - TaskGoalList_Struct *TaskGoalLists; + std::vector TaskGoalLists; int NumberOfLists; };