#include "stdafx.h"
#include "../../../SparAIContainer.h"
#include "../../PerceptualState.h"
#include "BunkerUnitRecordType.h"

BunkerUnitRecordType::BunkerUnitRecordType(UnitRecord* unitRecord, BWAPI::UnitType unitType)
  : TransportUnitRecordType(unitRecord, unitType)
  , m_troopsEstimationProcess(*this)
{
  assert(unitType == BWAPI::UnitTypes::Terran_Bunker);

  m_troopsEstimationProcess = new BunkerTroopsEstimationProcess(Spar->getPerceptualState(), this);
  m_troopsEstimationProcess->start();
}

void BunkerUnitRecordType::BunkerTroopsEstimationProcess::_output(std::ostream& out) const
{
  out << "Bunker troops estimation process (" << *m_bunker->getUnitRecord() << ")";
}

void BunkerUnitRecordType::BunkerTroopsEstimationProcess::onStart()
{
  m_bunkerDestroyID = m_bunker->getUnitRecord()->getIndividualUnitRecordDestroyEvent().subscribe(&m_bunkerDestroyEventHandler, NULL);
}

void BunkerUnitRecordType::BunkerTroopsEstimationProcess::onEnd()
{
  m_bunker->getUnitRecord()->getIndividualUnitRecordDestroyEvent().unsubscribe(m_bunkerDestroyID);
}