\hypertarget{classTaskManagerClass}{\section{\-Task\-Manager\-Class \-Class \-Reference}
\label{classTaskManagerClass}\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}}
}


{\ttfamily \#include $<$\-Task\-Manager.\-h$>$}

\subsection*{\-Public \-Member \-Functions}
\begin{DoxyCompactItemize}
\item 
\hyperlink{classTaskManagerClass_a10f1c3e99f17921b20de279f176cf47b}{\-Task\-Manager\-Class} ()
\item 
void \hyperlink{classTaskManagerClass_a43a645498582e154442f92eca0c29e1b}{on\-Discover} (\hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit} unit)
\item 
void \hyperlink{classTaskManagerClass_a42d96c02e84d735386aa46705be62782}{on\-Morph\-Renegade} (\hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit} unit, \hyperlink{Interface_8h_af5e942c6e6113009bb539d45bebff901}{\-Player} previous\-Player, \hyperlink{classBWAPI_1_1UnitType}{\-B\-W\-A\-P\-I\-::\-Unit\-Type} previous\-Type)
\item 
void \hyperlink{classTaskManagerClass_a62b7426a5a0eafbd93c23047420a3479}{on\-Destroy} (\hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit} unit)
\item 
void \hyperlink{classTaskManagerClass_ae1f90537b2b59ddca67c46c07d586149}{update} ()
\item 
void \hyperlink{classTaskManagerClass_ab2574923d432259045e4bda167cbad09}{remove\-Task} (\hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit} unit)
\item 
void \hyperlink{classTaskManagerClass_abef163cc5f8015aaf80c8f52f59b015e}{give\-Task} (\hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit} unit)
\item 
std\-::map$<$ int, int $>$ \hyperlink{classTaskManagerClass_a0e34cbb631dda8a4a80d7d9c7cf50c43}{earliest\-Free\-Times} (\hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit} unit, int priority, int last\-Block\-End, int max\-Time, int block\-Time\-Needed, bool allow\-Any\-Block\-Length)
\item 
void \hyperlink{classTaskManagerClass_a920f4334548502c426dd0d1fad7b15e1}{reserve\-Unit} (\hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit} unit, int time, int priority, int duration)
\item 
void \hyperlink{classTaskManagerClass_ae91eed09e9db962521c594cad857523e}{add\-Task} (\hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} task)
\item 
\hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} \hyperlink{classTaskManagerClass_ae414d771e1df59061415c9c881e78cce}{build} (\hyperlink{classBWAPI_1_1UnitType}{\-B\-W\-A\-P\-I\-::\-Unit\-Type} type, \hyperlink{Task_8h_a7b31e3712710b22657fc622787547497}{\-Task\-Type} task\-Type, \hyperlink{ReservedLocation_8h_a6492493e05598f5483be9ef982314a50}{\-Building\-Location} position=\hyperlink{structBuildingLocationDef_a9a2812e5e91bfae66c199469e9b04775a0037559c63116e839d2ed5e004248fde}{\-Building\-Location\-::\-Base})
\item 
\hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} \hyperlink{classTaskManagerClass_a229ff45aa7b562eac37192bf9cb98454}{upgrade} (\hyperlink{classBWAPI_1_1UpgradeType}{\-B\-W\-A\-P\-I\-::\-Upgrade\-Type} type, int level, \hyperlink{Task_8h_a7b31e3712710b22657fc622787547497}{\-Task\-Type} task\-Type)
\item 
\hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} \hyperlink{classTaskManagerClass_a2696536f9e984cd5aca5aa6de9320764}{research} (\hyperlink{classBWAPI_1_1TechType}{\-B\-W\-A\-P\-I\-::\-Tech\-Type} type, \hyperlink{Task_8h_a7b31e3712710b22657fc622787547497}{\-Task\-Type} task\-Type)
\end{DoxyCompactItemize}
\subsection*{\-Private \-Member \-Functions}
\begin{DoxyCompactItemize}
\item 
std\-::list$<$ \hyperlink{Task_8h_a7b31e3712710b22657fc622787547497}{\-Task\-Type} $>$ \hyperlink{classTaskManagerClass_abceeb71196d7f1a136170e71c2afaf85}{get\-Priority\-List} ()
\item 
bool \hyperlink{classTaskManagerClass_a73b8ef71c6b9a658d1bc0da01edcc447}{update\-Requirement} (\hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} task, \hyperlink{classRequirementGroup}{\-Requirement\-Group} requirement)
\end{DoxyCompactItemize}
\subsection*{\-Private \-Attributes}
\begin{DoxyCompactItemize}
\item 
std\-::map$<$ \hyperlink{classBWAPI_1_1UnitType}{\-B\-W\-A\-P\-I\-::\-Unit\-Type}, \*
std\-::map$<$ \hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit}, \hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} $>$ $>$ \hyperlink{classTaskManagerClass_a9d9fd58d74f544b558c24690394c7eb4}{m\-Unit\-Tasks}
\item 
std\-::map$<$ \hyperlink{Task_8h_a7b31e3712710b22657fc622787547497}{\-Task\-Type}, std\-::list\*
$<$ \hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} $>$ $>$ \hyperlink{classTaskManagerClass_a8656eab8553b93951599177d4b3e7128}{m\-Type\-Tasks}
\item 
std\-::set$<$ \hyperlink{Requirement_8h_a10d9e68ef4957f6a76bc93eb32bf2670}{\-Task\-Pointer} $>$ \hyperlink{classTaskManagerClass_aa355dfa0c11c1eb24c5cca63dd1b5200}{m\-Tasks}
\item 
std\-::map$<$ \hyperlink{Interface_8h_ab8fbb9e601c27f783b69f16c5a1fd40a}{\-Unit}, std\-::map$<$ int, \*
std\-::pair$<$ int, int $>$ $>$ $>$ \hyperlink{classTaskManagerClass_a934010ec91beae76e0c6fd1a0a9ca015}{m\-Reserved\-Units}
\end{DoxyCompactItemize}


\subsection{\-Detailed \-Description}


\-Definition at line 10 of file \-Task\-Manager.\-h.



\subsection{\-Constructor \& \-Destructor \-Documentation}
\hypertarget{classTaskManagerClass_a10f1c3e99f17921b20de279f176cf47b}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!\-Task\-Manager\-Class@{\-Task\-Manager\-Class}}
\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{\-Task\-Manager\-Class}]{\setlength{\rightskip}{0pt plus 5cm}{\bf \-Task\-Manager\-Class\-::\-Task\-Manager\-Class} (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a10f1c3e99f17921b20de279f176cf47b}


\-Definition at line 20 of file \-Task\-Manager.\-cpp.


\begin{DoxyCode}
{
}
\end{DoxyCode}


\subsection{\-Member \-Function \-Documentation}
\hypertarget{classTaskManagerClass_ae91eed09e9db962521c594cad857523e}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!add\-Task@{add\-Task}}
\index{add\-Task@{add\-Task}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{add\-Task}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::add\-Task} (
\begin{DoxyParamCaption}
\item[{{\bf \-Task\-Pointer}}]{task}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_ae91eed09e9db962521c594cad857523e}


\-Definition at line 358 of file \-Task\-Manager.\-cpp.



\-References \-L\-O\-G\-M\-E\-S\-S\-A\-G\-E, m\-Tasks, and m\-Type\-Tasks.



\-Referenced by build(), research(), and upgrade().


\begin{DoxyCode}
{
        LOGMESSAGE(String_Builder() << "TaskManager : New task added : " << 
      task->getTaskName() << " " << task->getOutputName());

        mTypeTasks[task->getType()].push_back(task);
        mTasks.insert(task);

        if(!task->hasEnded())
                task->updateRequirements();
}
\end{DoxyCode}


\-Here is the caller graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_ae91eed09e9db962521c594cad857523e_icgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_ae414d771e1df59061415c9c881e78cce}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!build@{build}}
\index{build@{build}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{build}]{\setlength{\rightskip}{0pt plus 5cm}{\bf \-Task\-Pointer} {\bf \-Task\-Manager\-Class\-::build} (
\begin{DoxyParamCaption}
\item[{{\bf \-B\-W\-A\-P\-I\-::\-Unit\-Type}}]{type, }
\item[{{\bf \-Task\-Type}}]{task\-Type, }
\item[{{\bf \-Building\-Location}}]{position = {\ttfamily {\bf \-Building\-Location\-::\-Base}}}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_ae414d771e1df59061415c9c881e78cce}


\-Definition at line 404 of file \-Task\-Manager.\-cpp.



\-References add\-Task(), \-B\-W\-A\-P\-I\-::\-Unit\-Type\-::get\-Race(), \-Singleton$<$ T $>$\-::\-Instance(), \-B\-W\-A\-P\-I\-::\-Unit\-Type\-::is\-Addon(), \-B\-W\-A\-P\-I\-::\-Unit\-Type\-::is\-Building(), \-B\-W\-A\-P\-I\-::\-Unit\-Types\-::\-None, \-B\-W\-A\-P\-I\-::\-Unit\-Types\-::\-Unknown, \-B\-W\-A\-P\-I\-::\-Unit\-Type\-::what\-Builds(), and \-B\-W\-A\-P\-I\-::\-Races\-::\-Zerg.


\begin{DoxyCode}
{
        if(type == BWAPI::UnitTypes::None || type == BWAPI::UnitTypes::Unknown)
                return TaskPointer();

        if(type.getRace() == BWAPI::Races::Zerg && type.isBuilding() == type.
      whatBuilds().first.isBuilding())
        {
                TaskPointer returnTask = TaskPointer(new MorphTask(taskType, 
      type));
                addTask(returnTask);
                MacroManager::Instance().onBuildTask(returnTask, type);
                return returnTask;
        }
        else
        {
                if(type.isBuilding())
                {
                        if(type.isAddon())
                        {
                                return TaskPointer(); // NYI
                        }
                        else
                        {
                                TaskPointer returnTask = TaskPointer(new 
      ConstructionTask(taskType, position, type));
                                addTask(returnTask);
                                MacroManager::Instance().onBuildTask(returnTask
      , type);
                                return returnTask;
                        }
                }
                else
                {
                        TaskPointer returnTask = TaskPointer(new TrainTask(
      taskType, type));
                        addTask(returnTask);
                        MacroManager::Instance().onBuildTask(returnTask, type);
                        return returnTask;
                }
        }

        return TaskPointer();
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_ae414d771e1df59061415c9c881e78cce_cgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a0e34cbb631dda8a4a80d7d9c7cf50c43}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!earliest\-Free\-Times@{earliest\-Free\-Times}}
\index{earliest\-Free\-Times@{earliest\-Free\-Times}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{earliest\-Free\-Times}]{\setlength{\rightskip}{0pt plus 5cm}std\-::map$<$ int, int $>$ {\bf \-Task\-Manager\-Class\-::earliest\-Free\-Times} (
\begin{DoxyParamCaption}
\item[{{\bf \-Unit}}]{unit, }
\item[{int}]{priority, }
\item[{int}]{last\-Block\-End, }
\item[{int}]{max\-Time, }
\item[{int}]{block\-Time\-Needed, }
\item[{bool}]{allow\-Any\-Block\-Length}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a0e34cbb631dda8a4a80d7d9c7cf50c43}


\-Definition at line 250 of file \-Task\-Manager.\-cpp.



\-References \-B\-W\-A\-P\-I\-::\-Broodwar, \-B\-W\-A\-P\-I\-::\-Game\-::get\-Frame\-Count(), \-L\-O\-G\-M\-E\-S\-S\-A\-G\-E, \-Requirement\-::max\-Time, m\-Reserved\-Units, and m\-Unit\-Tasks.


\begin{DoxyCode}
{
        std::map<int, int> suitableBlocks;

        // test this priority against the current task to test if we can
       override it
        TaskPointer currentTask = mUnitTasks[unit->getType()][unit];
        if(!currentTask)
        {
                LOGMESSAGE(String_Builder() << "TaskManager : Tried to access
       task for unit " << unit->getType().getName() << " that we don't control");
                return suitableBlocks;
        }

        if(priority <= currentTask->getPriority(unit))
        {
                // If we can't get the end time of the task
                int endTime = currentTask->getEndTime(unit);
                int frametime = BWAPI::Broodwar->getFrameCount();
                assert(endTime >= frametime);

                // Get the end time of the current task
                lastBlockEnd = std::max(endTime == frametime ? endTime+1 : 
      endTime, lastBlockEnd);
        }

        // If it has no end return nothing
        if(lastBlockEnd == Requirement::maxTime)
                return suitableBlocks;

        int currentFreeBlockStart = lastBlockEnd;
        int currentFreeBlockLength = 0;

        for(std::map<int, std::pair<int, int>>::iterator i = mReservedUnits[
      unit].begin(); i != mReservedUnits[unit].end(); ++i)
        {
                // This is before our current time slot so we don't need to
       worry about it
                if(i->first + i->second.second < lastBlockEnd)
                        continue;

                // this is after our current time so we should return
                if(i->first > maxTime)
                        return suitableBlocks;

                // We can move this block if we are higher priority
                bool canMoveThisBlock = priority > i->second.first;

                // How long the current block of time we have to fit in is
                currentFreeBlockLength += i->first - lastBlockEnd;
                
                // How long will this task last
                lastBlockEnd = i->second.second;

                // If it will last forever....
                if(lastBlockEnd == Requirement::maxTime)
                {
                        // If we can move this block, steal its time
                        if(canMoveThisBlock)
                                suitableBlocks[currentFreeBlockStart] = 
      Requirement::maxTime;
                        
                        //return as there is no more time to work with
                        return suitableBlocks;
                }
                
                // add the start time so we get the real end
                lastBlockEnd += i->first;

                // if we cannot move this block
                if(!canMoveThisBlock)
                {
                        // If its long enough, or we are looking we are looking
       for an endless slot
                        if(currentFreeBlockLength >= blockTimeNeeded || 
      allowAnyBlockLength)
                        {
                                suitableBlocks[currentFreeBlockStart] = 
      currentFreeBlockLength;
                        }

                        // reset the block length
                        currentFreeBlockLength = 0;
                        currentFreeBlockStart = lastBlockEnd;
                }
        }

        // If we made it this far we have the rest of the time for this task
        suitableBlocks[lastBlockEnd] = Requirement::maxTime;

        return suitableBlocks;
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a0e34cbb631dda8a4a80d7d9c7cf50c43_cgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_abceeb71196d7f1a136170e71c2afaf85}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!get\-Priority\-List@{get\-Priority\-List}}
\index{get\-Priority\-List@{get\-Priority\-List}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{get\-Priority\-List}]{\setlength{\rightskip}{0pt plus 5cm}std\-::list$<$ {\bf \-Task\-Type} $>$ {\bf \-Task\-Manager\-Class\-::get\-Priority\-List} (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}\label{classTaskManagerClass_abceeb71196d7f1a136170e71c2afaf85}


\-Definition at line 90 of file \-Task\-Manager.\-cpp.



\-References \-Task\-Type\-Def\-::\-Army, \-State\-Type\-Def\-::\-Build\-Army, \-Task\-Type\-Def\-::\-Build\-Order, \-Task\-Type\-Def\-::\-Defense, \-Task\-Type\-Def\-::\-Expansion, \-B\-W\-A\-P\-I\-::\-Orders\-::get\-Order(), \-Task\-Type\-Def\-::\-Highest, \-Singleton$<$ T $>$\-::\-Instance(), \-Task\-Type\-Def\-::\-Lowest, \-Order\-Def\-::\-Macro\-Can\-Tech, \-Task\-Type\-Def\-::\-Macro\-Extra\-Production, \-Task\-Type\-Def\-::\-Macro\-Tech, \-Task\-Type\-Def\-::\-Macro\-Urgent, \-Task\-Type\-Def\-::\-Medium, \-Task\-Type\-Def\-::\-Refinery\-Manager, \-Task\-Type\-Def\-::\-Scout, \-Task\-Type\-Def\-::\-Supply, \-State\-Type\-Def\-::\-Tech\-High, \-State\-Type\-Def\-::\-Tech\-Normal, and \-Task\-Type\-Def\-::\-Worker.



\-Referenced by update().


\begin{DoxyCode}
{
        std::list<TaskType> returnList;

        //Thing to consider for sorts these:
        // If I am vulnerable to counter attack / have no map control, place
       defense higher
        // If I am not behind on army size but its not safe to attack, tech
        // If I am not behind on army size but its safe to attack, produce
        // If I'm behind on army supply, produce

        StateType currentState = GameProgressDetection::Instance().getState();
        
        returnList.push_back(TaskType::Highest);
        returnList.push_back(TaskType::Supply);
        returnList.push_back(TaskType::Worker);
        returnList.push_back(TaskType::RefineryManager);
        returnList.push_back(TaskType::MacroUrgent);
        returnList.push_back(TaskType::Scout);
        returnList.push_back(TaskType::Expansion);

        if(currentState == StateType::TechHigh && BuildOrderManager::Instance()
      .getOrder(Order::MacroCanTech))
        {
                returnList.push_back(TaskType::BuildOrder);
                returnList.push_back(TaskType::MacroTech);
                returnList.push_back(TaskType::Defense);
                returnList.push_back(TaskType::Army);
        }
        else
        {
                returnList.push_back(TaskType::Army);
                returnList.push_back(TaskType::Defense);
                returnList.push_back(TaskType::BuildOrder);
        }
        
        returnList.push_back(TaskType::Medium);

        if(currentState == StateType::TechNormal && BuildOrderManager::Instance
      ().getOrder(Order::MacroCanTech))
                returnList.push_back(TaskType::MacroTech);

        returnList.push_back(TaskType::MacroExtraProduction);

        if(currentState == StateType::BuildArmy && BuildOrderManager::Instance(
      ).getOrder(Order::MacroCanTech))
                returnList.push_back(TaskType::MacroTech);

        returnList.push_back(TaskType::Lowest);

        return returnList;
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_abceeb71196d7f1a136170e71c2afaf85_cgraph}
\end{center}
\end{figure}




\-Here is the caller graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_abceeb71196d7f1a136170e71c2afaf85_icgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_abef163cc5f8015aaf80c8f52f59b015e}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!give\-Task@{give\-Task}}
\index{give\-Task@{give\-Task}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{give\-Task}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::give\-Task} (
\begin{DoxyParamCaption}
\item[{{\bf \-Unit}}]{unit}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_abef163cc5f8015aaf80c8f52f59b015e}


\-Definition at line 215 of file \-Task\-Manager.\-cpp.



\-References \-L\-O\-G\-M\-E\-S\-S\-A\-G\-E, \-Task\-Type\-Def\-::\-Lowest, m\-Tasks, m\-Type\-Tasks, and m\-Unit\-Tasks.



\-Referenced by on\-Discover(), on\-Morph\-Renegade(), and remove\-Task().


\begin{DoxyCode}
{
        TaskPointer bestTask;
        int priority = 0;

        for each(TaskPointer task in mTasks)
        {
                if(task->waitingForUnit(unit))
                {
                        int thisPriority = task->getPriority(unit);
                        if(thisPriority > priority)
                        {
                                priority = thisPriority;
                                bestTask = task;
                        }
                }
        }

        if(bestTask)
        {
                LOGMESSAGE(String_Builder() << "TaskManager : Given new unit " 
      << unit->getType().getName() << " to " << bestTask->getTaskName() << " " << 
      bestTask->getOutputName());
                mUnitTasks[unit->getType()][unit] = bestTask;
                bestTask->giveUnit(unit);
        }
        else
        {
                LOGMESSAGE(String_Builder() << "TaskManager : Created idle task
       for " << unit->getType().getName());
                TaskPointer idleTask(new IdleTask(TaskType::Lowest));
                mUnitTasks[unit->getType()][unit] = idleTask;
                mTasks.insert(idleTask);
                mTypeTasks[idleTask->getType()].push_back(idleTask);
                idleTask->giveUnit(unit);
        }
}
\end{DoxyCode}


\-Here is the caller graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_abef163cc5f8015aaf80c8f52f59b015e_icgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a62b7426a5a0eafbd93c23047420a3479}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!on\-Destroy@{on\-Destroy}}
\index{on\-Destroy@{on\-Destroy}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{on\-Destroy}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::on\-Destroy} (
\begin{DoxyParamCaption}
\item[{{\bf \-Unit}}]{unit}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a62b7426a5a0eafbd93c23047420a3479}


\-Definition at line 194 of file \-Task\-Manager.\-cpp.



\-References remove\-Task().


\begin{DoxyCode}
{
        removeTask(unit);
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a62b7426a5a0eafbd93c23047420a3479_cgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a43a645498582e154442f92eca0c29e1b}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!on\-Discover@{on\-Discover}}
\index{on\-Discover@{on\-Discover}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{on\-Discover}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::on\-Discover} (
\begin{DoxyParamCaption}
\item[{{\bf \-Unit}}]{unit}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a43a645498582e154442f92eca0c29e1b}


\-Definition at line 139 of file \-Task\-Manager.\-cpp.



\-References \-B\-W\-A\-P\-I\-::\-Broodwar, give\-Task(), and \-B\-W\-A\-P\-I\-::\-Game\-::self().


\begin{DoxyCode}
{
        if(unit->getPlayer() != BWAPI::Broodwar->self())
                return;

        giveTask(unit);
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a43a645498582e154442f92eca0c29e1b_cgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a42d96c02e84d735386aa46705be62782}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!on\-Morph\-Renegade@{on\-Morph\-Renegade}}
\index{on\-Morph\-Renegade@{on\-Morph\-Renegade}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{on\-Morph\-Renegade}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::on\-Morph\-Renegade} (
\begin{DoxyParamCaption}
\item[{{\bf \-Unit}}]{unit, }
\item[{{\bf \-Player}}]{previous\-Player, }
\item[{{\bf \-B\-W\-A\-P\-I\-::\-Unit\-Type}}]{previous\-Type}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a42d96c02e84d735386aa46705be62782}


\-Definition at line 147 of file \-Task\-Manager.\-cpp.



\-References \-B\-W\-A\-P\-I\-::\-Broodwar, \-Access\-Type\-Def\-::\-Full, give\-Task(), m\-Unit\-Tasks, \-B\-W\-A\-P\-I\-::\-Unit\-Types\-::\-None, and \-B\-W\-A\-P\-I\-::\-Game\-::self().


\begin{DoxyCode}
{
        if(previousPlayer != NULL)
        {
                if(previousPlayer == BWAPI::Broodwar->self())
                {
                        if(previousType != BWAPI::UnitTypes::None)
                        {
                                mUnitTasks[previousType][unit]->returnUnit(unit
      );
                                if(!mUnitTasks[previousType][unit]->hasEnded())
                                        mUnitTasks[previousType][unit]->
      updateRequirements();
                                mUnitTasks[previousType].erase(unit);
                        }
                        else
                        {
                                mUnitTasks[unit->getType()][unit]->returnUnit(
      unit);
                                if(!mUnitTasks[unit->getType()][unit]->hasEnded
      ())
                                        mUnitTasks[unit->getType()][unit]->
      updateRequirements();
                                mUnitTasks[unit->getType()].erase(unit);
                        }
                }
                else if(unit->getPlayer() == BWAPI::Broodwar->self())
                {
                        giveTask(unit);
                }
        }
        else if(previousType != BWAPI::UnitTypes::None && unit->getPlayer() == 
      BWAPI::Broodwar->self())
        {
                if(mUnitTasks[previousType][unit]->morph(unit, previousType))
                {
                        mUnitTasks[previousType][unit]->returnUnit(unit);
                        if(!mUnitTasks[previousType][unit]->hasEnded())
                                mUnitTasks[previousType][unit]->
      updateRequirements();
                        mUnitTasks[previousType].erase(unit);

                        if(unit->accessibility() == AccessType::Full)
                                giveTask(unit);
                }
                else
                {
                        TaskPointer task = mUnitTasks[previousType][unit];
                        mUnitTasks[previousType].erase(unit);
                        mUnitTasks[unit->getType()][unit] = task;
                }
        }
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a42d96c02e84d735386aa46705be62782_cgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_ab2574923d432259045e4bda167cbad09}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!remove\-Task@{remove\-Task}}
\index{remove\-Task@{remove\-Task}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{remove\-Task}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::remove\-Task} (
\begin{DoxyParamCaption}
\item[{{\bf \-Unit}}]{unit}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_ab2574923d432259045e4bda167cbad09}


\-Definition at line 199 of file \-Task\-Manager.\-cpp.



\-References \-Access\-Type\-Def\-::\-Full, give\-Task(), \-L\-O\-G\-M\-E\-S\-S\-A\-G\-E, and m\-Unit\-Tasks.



\-Referenced by on\-Destroy(), and update().


\begin{DoxyCode}
{
        if(mUnitTasks[unit->getType()].find(unit) == mUnitTasks[unit->getType()
      ].end())
                return;

        LOGMESSAGE(String_Builder() << "TaskManager : Removed Unit " << unit->
      getType().getName() << " from " << mUnitTasks[unit->getType()][unit]->getTaskName
      () << " " << mUnitTasks[unit->getType()][unit]->getOutputName());

        mUnitTasks[unit->getType()][unit]->returnUnit(unit);
        if(!mUnitTasks[unit->getType()][unit]->hasEnded())
                mUnitTasks[unit->getType()][unit]->updateRequirements();
        mUnitTasks[unit->getType()].erase(unit);

        if(unit->accessibility() == AccessType::Full)
                giveTask(unit);
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_ab2574923d432259045e4bda167cbad09_cgraph}
\end{center}
\end{figure}




\-Here is the caller graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_ab2574923d432259045e4bda167cbad09_icgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a2696536f9e984cd5aca5aa6de9320764}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!research@{research}}
\index{research@{research}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{research}]{\setlength{\rightskip}{0pt plus 5cm}{\bf \-Task\-Pointer} {\bf \-Task\-Manager\-Class\-::research} (
\begin{DoxyParamCaption}
\item[{{\bf \-B\-W\-A\-P\-I\-::\-Tech\-Type}}]{type, }
\item[{{\bf \-Task\-Type}}]{task\-Type}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a2696536f9e984cd5aca5aa6de9320764}


\-Definition at line 452 of file \-Task\-Manager.\-cpp.



\-References add\-Task(), and \-Singleton$<$ T $>$\-::\-Instance().


\begin{DoxyCode}
{
        TaskPointer returnTask = TaskPointer(new TechTask(taskType, type));
        addTask(returnTask);
        MacroManager::Instance().onTechTask(returnTask, type);
        return returnTask;
}\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a2696536f9e984cd5aca5aa6de9320764_cgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a920f4334548502c426dd0d1fad7b15e1}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!reserve\-Unit@{reserve\-Unit}}
\index{reserve\-Unit@{reserve\-Unit}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{reserve\-Unit}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::reserve\-Unit} (
\begin{DoxyParamCaption}
\item[{{\bf \-Unit}}]{unit, }
\item[{int}]{time, }
\item[{int}]{priority, }
\item[{int}]{duration}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a920f4334548502c426dd0d1fad7b15e1}


\-Definition at line 334 of file \-Task\-Manager.\-cpp.



\-References m\-Reserved\-Units.


\begin{DoxyCode}
{
        // TODO: change from a map to a sorted vector or sumin, should be
       faster at updating times
        mReservedUnits[unit][time] = std::pair<int, int>(priority, duration);

        int lastTaskEndTime = 0;
        for(std::map<int, std::pair<int, int>>::iterator i = mReservedUnits[
      unit].begin(); i != mReservedUnits[unit].end();)
        {
                if(lastTaskEndTime > i->first)
                {
                        std::pair<int, int> tempTask = i->second;
                        mReservedUnits[unit].erase(i++);
                        mReservedUnits[unit][lastTaskEndTime] = tempTask;

                        lastTaskEndTime += tempTask.second;
                }
                else
                {
                        lastTaskEndTime = i->first + i->second.second;
                        ++i;
                }
        }
}
\end{DoxyCode}
\hypertarget{classTaskManagerClass_ae1f90537b2b59ddca67c46c07d586149}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!update@{update}}
\index{update@{update}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{update}]{\setlength{\rightskip}{0pt plus 5cm}void {\bf \-Task\-Manager\-Class\-::update} (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_ae1f90537b2b59ddca67c46c07d586149}


\-Definition at line 24 of file \-Task\-Manager.\-cpp.



\-References get\-Priority\-List(), \-Singleton$<$ T $>$\-::\-Instance(), m\-Reserved\-Units, m\-Tasks, m\-Type\-Tasks, remove\-Task(), and update\-Requirement().


\begin{DoxyCode}
{
        for each(const TaskPointer &task in mTasks)
        {
                if(task->preUpdate())
                {
                        for each(Unit unit in task->getFinishedUnits())
                                removeTask(unit);
                }
        }

        // Clear previous reservations
        ResourceTracker::Instance().reset();
        mReservedUnits.clear();

        for each(TaskType type in getPriorityList())
        {
                std::map<TaskType, std::list<TaskPointer>>::iterator l = 
      mTypeTasks.find(type);

                if(l != mTypeTasks.end())
                {
                        for(std::list<TaskPointer>::iterator i = l->second.
      begin(); i != l->second.end(); ++i)
                        {
                                if((*i)->hasEnded())
                                        continue;

                                (*i)->updateRequirements(boost::bind<bool>(&
      TaskManagerClass::updateRequirement, this, *i, _1));
                        }
                }
        }

        for(std::map<TaskType, std::list<TaskPointer>>::iterator itFirst = 
      mTypeTasks.begin(); itFirst != mTypeTasks.end(); ++itFirst)
        {
                for(std::list<TaskPointer>::iterator it = itFirst->second.begin
      (); it != itFirst->second.end();)
                {
                        if((*it)->update())
                        {
                                //TODO: shouldn't have to but don't delete if
       it has control of units or just assert
                                /*
                                int count = 0;
                                for(std::map<BWAPI::UnitType, std::map<Unit,
       TaskPointer>>::iterator it2 = mUnitTasks.begin(); it2 != mUnitTasks.end(); ++it2)
                                {
                                        for(std::map<Unit,
       TaskPointer>::iterator it3 = it2->second.begin(); it3 != it2->second.end(); ++it3)
                                        {
                                                if(it3->second == *it)
                                                {
                                                        ++count;
                                                }
                                        }
                                }

                                if(count > 0)
                                {
                                        LOGMESSAGE(String_Builder() <<
       "TaskManager : Task " << (*it)->getTaskName() << " " << (*it)->getOutputName() << "
       deleted while still controlling " << count << " units");
                                }
                                */

                                mTasks.erase(*it);
                                itFirst->second.erase(it++);
                        }
                        else
                                ++it;
                }
        }
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_ae1f90537b2b59ddca67c46c07d586149_cgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a73b8ef71c6b9a658d1bc0da01edcc447}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!update\-Requirement@{update\-Requirement}}
\index{update\-Requirement@{update\-Requirement}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{update\-Requirement}]{\setlength{\rightskip}{0pt plus 5cm}bool {\bf \-Task\-Manager\-Class\-::update\-Requirement} (
\begin{DoxyParamCaption}
\item[{{\bf \-Task\-Pointer}}]{task, }
\item[{{\bf \-Requirement\-Group}}]{requirement}
\end{DoxyParamCaption}
)\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}\label{classTaskManagerClass_a73b8ef71c6b9a658d1bc0da01edcc447}


\-Definition at line 369 of file \-Task\-Manager.\-cpp.



\-References \-B\-W\-A\-P\-I\-::\-Broodwar, \-Requirement\-Group\-::earliest\-Time(), \-Requirement\-Group\-::empty(), \-B\-W\-A\-P\-I\-::\-Game\-::get\-Frame\-Count(), \-Requirement\-Group\-::get\-Units(), \-L\-O\-G\-M\-E\-S\-S\-A\-G\-E, m\-Unit\-Tasks, and \-Requirement\-Group\-::reserve().



\-Referenced by update().


\begin{DoxyCode}
{
        if(!requirement.empty())
        {
                std::pair<int, int> earliestTime = requirement.earliestTime();
                task->setRequiredSatisfyTime(requirement, earliestTime.first, 
      earliestTime.second);

                if(earliestTime.first - earliestTime.second <= BWAPI::Broodwar
      ->getFrameCount())
                {
                        for each(Unit unit in requirement.getUnits())
                        {
                                TaskPointer oldTask = mUnitTasks[unit->getType(
      )][unit];
                                oldTask->returnUnit(unit);
                                if(!oldTask->hasEnded())
                                        oldTask->updateRequirements();

                                mUnitTasks[unit->getType()][unit] = task;

                                LOGMESSAGE(String_Builder() << "TaskManager :
       Taken " << unit->getType().getName() << " from " << oldTask->getTaskName() << " "
       << oldTask->getOutputName());
                                LOGMESSAGE(String_Builder() << "TaskManager :
       Given " << unit->getType().getName() << " to " << task->getTaskName() << " " << 
      task->getOutputName());
                                task->giveUnit(unit);
                        }

                        return true;
                }
                else
                {
                        requirement.reserve(earliestTime.first);
                        //TODO see what can be done to make this task happen
       sooner
                }
        }

        return false;
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a73b8ef71c6b9a658d1bc0da01edcc447_cgraph}
\end{center}
\end{figure}




\-Here is the caller graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a73b8ef71c6b9a658d1bc0da01edcc447_icgraph}
\end{center}
\end{figure}


\hypertarget{classTaskManagerClass_a229ff45aa7b562eac37192bf9cb98454}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!upgrade@{upgrade}}
\index{upgrade@{upgrade}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{upgrade}]{\setlength{\rightskip}{0pt plus 5cm}{\bf \-Task\-Pointer} {\bf \-Task\-Manager\-Class\-::upgrade} (
\begin{DoxyParamCaption}
\item[{{\bf \-B\-W\-A\-P\-I\-::\-Upgrade\-Type}}]{type, }
\item[{int}]{level, }
\item[{{\bf \-Task\-Type}}]{task\-Type}
\end{DoxyParamCaption}
)}}\label{classTaskManagerClass_a229ff45aa7b562eac37192bf9cb98454}


\-Definition at line 444 of file \-Task\-Manager.\-cpp.



\-References add\-Task(), and \-Singleton$<$ T $>$\-::\-Instance().


\begin{DoxyCode}
{
        TaskPointer returnTask = TaskPointer(new UpgradeTask(taskType, type, 
      level));
        addTask(returnTask);
        MacroManager::Instance().onUpgradeTask(returnTask, type, level);
        return returnTask;
}
\end{DoxyCode}


\-Here is the call graph for this function\-:\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classTaskManagerClass_a229ff45aa7b562eac37192bf9cb98454_cgraph}
\end{center}
\end{figure}




\subsection{\-Member \-Data \-Documentation}
\hypertarget{classTaskManagerClass_a934010ec91beae76e0c6fd1a0a9ca015}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!m\-Reserved\-Units@{m\-Reserved\-Units}}
\index{m\-Reserved\-Units@{m\-Reserved\-Units}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{m\-Reserved\-Units}]{\setlength{\rightskip}{0pt plus 5cm}std\-::map$<${\bf \-Unit}, std\-::map$<$int, std\-::pair$<$int, int$>$ $>$ $>$ {\bf \-Task\-Manager\-Class\-::m\-Reserved\-Units}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}\label{classTaskManagerClass_a934010ec91beae76e0c6fd1a0a9ca015}


\-Definition at line 43 of file \-Task\-Manager.\-h.



\-Referenced by earliest\-Free\-Times(), reserve\-Unit(), and update().

\hypertarget{classTaskManagerClass_aa355dfa0c11c1eb24c5cca63dd1b5200}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!m\-Tasks@{m\-Tasks}}
\index{m\-Tasks@{m\-Tasks}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{m\-Tasks}]{\setlength{\rightskip}{0pt plus 5cm}std\-::set$<${\bf \-Task\-Pointer}$>$ {\bf \-Task\-Manager\-Class\-::m\-Tasks}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}\label{classTaskManagerClass_aa355dfa0c11c1eb24c5cca63dd1b5200}


\-Definition at line 41 of file \-Task\-Manager.\-h.



\-Referenced by add\-Task(), give\-Task(), and update().

\hypertarget{classTaskManagerClass_a8656eab8553b93951599177d4b3e7128}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!m\-Type\-Tasks@{m\-Type\-Tasks}}
\index{m\-Type\-Tasks@{m\-Type\-Tasks}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{m\-Type\-Tasks}]{\setlength{\rightskip}{0pt plus 5cm}std\-::map$<${\bf \-Task\-Type}, std\-::list$<${\bf \-Task\-Pointer}$>$ $>$ {\bf \-Task\-Manager\-Class\-::m\-Type\-Tasks}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}\label{classTaskManagerClass_a8656eab8553b93951599177d4b3e7128}


\-Definition at line 40 of file \-Task\-Manager.\-h.



\-Referenced by add\-Task(), give\-Task(), and update().

\hypertarget{classTaskManagerClass_a9d9fd58d74f544b558c24690394c7eb4}{\index{\-Task\-Manager\-Class@{\-Task\-Manager\-Class}!m\-Unit\-Tasks@{m\-Unit\-Tasks}}
\index{m\-Unit\-Tasks@{m\-Unit\-Tasks}!TaskManagerClass@{\-Task\-Manager\-Class}}
\subsubsection[{m\-Unit\-Tasks}]{\setlength{\rightskip}{0pt plus 5cm}std\-::map$<${\bf \-B\-W\-A\-P\-I\-::\-Unit\-Type}, std\-::map$<${\bf \-Unit}, {\bf \-Task\-Pointer}$>$ $>$ {\bf \-Task\-Manager\-Class\-::m\-Unit\-Tasks}\hspace{0.3cm}{\ttfamily  \mbox{[}private\mbox{]}}}}\label{classTaskManagerClass_a9d9fd58d74f544b558c24690394c7eb4}


\-Definition at line 38 of file \-Task\-Manager.\-h.



\-Referenced by earliest\-Free\-Times(), give\-Task(), on\-Morph\-Renegade(), remove\-Task(), and update\-Requirement().



\-The documentation for this class was generated from the following files\-:\begin{DoxyCompactItemize}
\item 
\-Skynet/\-Skynet/\hyperlink{TaskManager_8h}{\-Task\-Manager.\-h}\item 
\-Skynet/\-Skynet/\hyperlink{TaskManager_8cpp}{\-Task\-Manager.\-cpp}\end{DoxyCompactItemize}
