#include "stdafx.h"
#include "Build.h"
#include "../../../../PerceptualState/Locations/Static/AutoPopulated/AutoPopulatedLocation.h"
#include "../../../../PerceptualState/World/CurrentWorld.h"

const Build::TerminationMode Build::TerminatedNoSpace;
const Build::TerminationMode Build::TerminatedNoWorker;
const Build::TerminationMode Build::TerminatedBuildingDestroyed;
const Build::TerminationMode Build::TerminatedTechUnavailable;

Build::Build(const Process* parent, unsigned int priority, AutoPopulatedLocation* location, BWAPI::UnitType buildingType)
  : GroupTacticalAction(parent, priority)
  , TacticalAction(parent, priority)
  , Process(parent)
  , m_buildingStartedEvent(*this)
  , m_buildingCompletedEvent(*this)
  , m_location(*this, location)
  , m_buildingType(buildingType)
  , m_buildingTypeObject(CurrentWorld::getBuildingTypeObject(buildingType))
{
  assert(m_buildingType.isBuilding());
  assert(m_buildingTypeObject != NULL);

  //m_precondition = new AndExp();

  //const std::map<BWAPI::UnitType, int>& requiredUnits = m_buildingType.requiredUnits();
  //for (std::map<BWAPI::UnitType, int>::const_iterator it = requiredUnits.begin(); it != requiredUnits.end(); ++it)
  //{
  //  m_precondition.add(new UnitTypeInstanceCompleted(it->first));
  //}
  //BWAPI::TechType requiredTech = m_buildingType.requiredTech();
  //if (requiredTech != BWAPI::TechTypes::None)
  //{
  //  m_precondition.add(new TechResearched(CurrentWorld::getTechTypeObject(requiredTech)));
  //}
  //assert(whatBuilds.first == BWAPI::UnitTypes::None);

  //m_effect = new BuildingIdle(m_buildingType);
}

void Build::_output(std::ostream& out) const
{
  GroupTacticalAction::_output(out);

  out << "Build(" << m_buildingType.getName() << ", " << *m_location << ")";
}
