CIVTask * CClientTaskManager::GetClientTaskFromGameTask(IVTask * pGameTask, bool bCreateIfNotExist) { // Do we have an invalid game task pointer? if(!pGameTask) return NULL; for(std::list<ClientTaskPair *>::iterator iter = m_taskList.begin(); iter != m_taskList.end(); iter++) { // Is this the client task pair we are looking for? if((*iter)->pGameTask == pGameTask) return (*iter)->pClientTask; } // Create the client task if requested if(bCreateIfNotExist) { // Create a temporary instance CIVTask * pTempClientTask = new CIVTask(pGameTask); // Is this task a simple task? bool bIsSimple = pTempClientTask->IsSimple(); // Delete the temporary instance delete pTempClientTask; // Create the client task instance CIVTask * pClientTask = NULL; if(bIsSimple) pClientTask = new CIVTaskSimple((IVTaskSimple *)pGameTask); else pClientTask = new CIVTaskComplex((IVTaskComplex *)pGameTask); // Add the task AddTask(pClientTask); // Return the new client task instance return pClientTask; } // No client task found return NULL; }
CIVTask * CTaskManager::GetClientTaskFromGameTask(IVTask * pGameTask, bool bCreateIfNotExist) { // Do we have an invalid task pointer? if(!pGameTask) return NULL; // Loop through all the client tasks for(auto pTask:m_taskList) { // Is this the client task pair we are looking for? if(pTask->pGameTask == pGameTask) return pTask->pClientTask; } // Create the task if requested if(bCreateIfNotExist) { // Create a temp intance CIVTask * pTempClientTask = new CIVTask(pGameTask); // Is this task simple? bool bIsSimple = pTempClientTask->IsSimple(); // Delete the temporary instance delete pTempClientTask; // Create the client task instance CIVTask * pClientTask = NULL; if(bIsSimple) pClientTask = new CIVTaskSimple((IVTaskSimple *)pGameTask); else pClientTask = new CIVTaskComplex((IVTaskComplex *)pGameTask); // Add the task AddTask(pClientTask); // Return the new task return pClientTask; } return NULL; }