BWAPI
Skynet/Skynet/DropAction.cpp
Go to the documentation of this file.
00001 #include "DropAction.h"
00002 
00003 bool DropAction::update(const Goal &squadGoal, const UnitGroup &squadUnitGroup)
00004 {
00005         return false;
00006 }
00007 
00008 void DropAction::removeUnit(Unit unit)
00009 {
00010         mUnits.erase(unit);
00011 
00012         if(unit != mShuttle)
00013                 mFreeSpace += unit->getType().spaceRequired();
00014         else
00015                 mShuttle = StaticUnits::nullunit;
00016 }
00017 
00018 void DropAction::addUnit(Unit unit)
00019 {
00020         mUnits.insert(unit);
00021 
00022         mFreeSpace -= unit->getType().spaceRequired();
00023 }
00024 
00025 bool DropAction::requestingExtraUnits()
00026 {
00027         return mFreeSpace > 0;
00028 }
00029 
00030 std::vector<std::map<BWAPI::UnitType, int>> DropAction::getRequestedUnits()
00031 {
00032         std::vector<std::map<BWAPI::UnitType, int>> returnData;
00033 
00034         int maxNumOfBig = mFreeSpace / BWAPI::UnitTypes::Protoss_Reaver.spaceRequired();
00035         int maxNumOfSmall = mFreeSpace / BWAPI::UnitTypes::Protoss_Zealot.spaceRequired();
00036 
00037         int currentBig = maxNumOfBig;
00038         int currentSmall = 0;
00039 
00040         for(;;)
00041         {
00042                 std::map<BWAPI::UnitType, int> currentData;
00043 
00044                 currentData[BWAPI::UnitTypes::Protoss_Reaver] = currentBig;
00045                 currentData[BWAPI::UnitTypes::Protoss_Zealot] = currentSmall;
00046 
00047                 int spaceForSmall = mFreeSpace;
00048                 spaceForSmall -= currentBig * BWAPI::UnitTypes::Protoss_Reaver.spaceRequired();
00049                 spaceForSmall -= currentBig * BWAPI::UnitTypes::Protoss_Zealot.spaceRequired();
00050 
00051                 if(spaceForSmall >= BWAPI::UnitTypes::Protoss_Zealot.spaceRequired())
00052                         ++currentSmall;
00053                 else if(currentBig == 0)
00054                         break;
00055                 else
00056                 {
00057                         currentSmall = 0;
00058                         --currentBig;
00059                 }
00060         }
00061 
00062         return returnData;
00063 }
00064 
00065 bool DropAction::finishedWithAUnit()
00066 {
00067         return false;
00068 }
00069 
00070 UnitGroup DropAction::getFinishedUnits()
00071 {
00072         return UnitGroup();
00073 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines