BWAPI
Skynet/Skynet/TaskPump.cpp
Go to the documentation of this file.
00001 #include "TaskPump.h"
00002 
00003 #include "TaskManager.h"
00004 
00005 TaskPump::TaskPump(BWAPI::UnitType type, TaskType taskType, BuildingLocation location)
00006         : mType(type)
00007         , mTaskType(taskType)
00008         , mLocation(location)
00009         , mTargetQuantity(0)
00010 {
00011 }
00012 
00013 void TaskPump::update()
00014 {
00015         for(std::list<TaskPointer>::iterator it = mQueuedItems.begin(); it != mQueuedItems.end();)
00016         {
00017                 if((*it)->hasEnded())
00018                         mQueuedItems.erase(it++);
00019                 else
00020                         ++it;
00021         }
00022 
00023         int currentTotal = mQueuedItems.size();
00024         for(std::list<TaskPointer>::iterator it2 = mQueuedItems.begin(); it2 != mQueuedItems.end();)
00025         {
00026                 if(currentTotal > mTargetQuantity && !(*it2)->inProgress())
00027                 {
00028                         (*it2)->cancel();
00029                         mQueuedItems.erase(it2++);
00030                         --currentTotal;
00031                 }
00032                 else
00033                         ++it2;
00034         }
00035 
00036         while(currentTotal > mTargetQuantity && !mQueuedItems.empty())
00037         {
00038                 (*mQueuedItems.rbegin())->cancel();
00039                 mQueuedItems.pop_back();
00040                 --currentTotal;
00041         }
00042 
00043         while(currentTotal < mTargetQuantity)
00044         {
00045                 TaskPointer tempPtr = TaskManager::Instance().build(mType, mTaskType, mLocation);
00046 
00047                 mQueuedItems.push_back(tempPtr);
00048 
00049                 ++currentTotal;
00050         }
00051 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines