#include "stdafx.h"
#include "BuildCannonsProcess.h"
#include "../Layer3Script.h"
#include "../../../../PerceptualState/PerceptualState.h"
#include "../../../../PerceptualState/Locations/Static/AutoPopulated/Region.h"

// TODO

void BuildCannonsProcess::run()
{
#if 0
  if (/*why to build a canon*/ CurrentWorld::Forge->isCreatable()) 
  {
    std::pair<Map::base_location_const_iterator, Map::base_location_const_iterator> baseLocations = 
      Spar->getPerceptualState()->getMap()->getBaseLocations();
    for (Map::base_location_const_iterator it = baseLocations.first; it != baseLocations.second; ++it)
    {
      if((*it)->getNbCompletedOwnUnits(BWAPI::UnitTypes::Protoss_Nexus) > 0)
      {
        Region* region = (*it)->getParent();
        if(region->getNbOwnUnits(BWAPI::UnitTypes::Protoss_Photon_Cannon) == 0)
        {
          if(region->getNbCompletedOwnUnits(BWAPI::UnitTypes::Protoss_Pylon) > 0)
          {
            Build* buildCannon = Layer3Script::getInstance().getLayer2().instantiateBuild(
              this,
              PRIORITY_BUILD_CANNONS,
              region, 
              BWAPI::UnitTypes::Protoss_Photon_Cannon);
            m_buildCannons.add(buildCannon);
            buildCannon->start();
          }
        }
      }
    }
    /*const Resources surplus = m_layer3Script.getLayer2().getAvailableResources(PRIORITY_BUILD_CANNONS);
    if (surplus.getMinerals() >= BWAPI::UnitTypes::Protoss_Photon_Cannon.mineralPrice()
    && surplus.getGas() >= BWAPI::UnitTypes::Protoss_Photon_Cannon.gasPrice())
    {
    Build* buildCannon = new Build(
    PRIORITY_BUILD_CANNONS,
    Spar->getPerceptualState()->getMap(), 
    BWAPI::UnitTypes::Protoss_Photon_Cannon);
    m_buildCannons.add(buildCannon);
    buildCannon->start();
    }*/
  }
#endif
}
