#pragma once
#include "../../../../Utils/Process/FSM/Condition.h"

class BuildingStarted : public Condition
{
public:
  BuildingStarted(BWAPI::TilePosition target, BWAPI::UnitType type, BWAPI::Unit*& building)
    : m_target(target)
    , m_type(type)
    , m_building(building)
  {
  }

  bool evaluate() const
  {
    const std::set<BWAPI::Unit*>& units = BWAPI::Broodwar->getUnitsOnTile(m_target.x(),m_target.y());
    for(std::set<BWAPI::Unit*>::const_iterator it = units.begin(); m_building == NULL && it!=units.end(); ++it)
    {
      if((*it)->getType() == m_type && (*it)->getPlayer() == BWAPI::Broodwar->self())
        m_building = *it;
    }
    return m_building != NULL;
  }

protected:
  const BWAPI::TilePosition m_target;
  const BWAPI::UnitType m_type;
  BWAPI::Unit*& m_building; // output

private:

  //m_type is uncopyable
  BuildingStarted& operator= (const BuildingStarted & rhs);
};
