#include "stdafx.h"
#include "SparAIContainer.h"

SparAIContainer::SparAIContainer(const Process* parent,
                                 Scheduler* scheduler,
                                 MP::MPScheduler * mpScheduler,
                                 PerceptualState* perceptualState,
                                 Timer* timer)
  : detail::ProcessHelper(parent)
  , m_schedulerPtr(scheduler)
  , m_mpSchedulerPtr(mpScheduler)
  , m_perceptualStatePtr(perceptualState)
  , m_timerPtr(timer)
{
  Spar = this;
  SPAR_LOG(LogTypes.GENERAL, "Analyzing map...");
  BWTA::readMap();
  BWTA::analyze();
  SPAR_LOG(LogTypes.GENERAL, "Done.");
}

SparAIContainer::~SparAIContainer()
{
#ifdef USE_SPAR_LOG
  SparLogger::get().stopThread();
#endif
}

void SparAIContainer::onStartAIModule()
{
  Process::start();
#ifdef _DEBUG_COMPONENT
  Component::_setComponentsDebugInfo();
#endif
}

void SparAIContainer::onEndAIModule(bool isWinner)
{
  m_isWinner = isWinner;

  Process::terminate(Success);
#ifdef _DEBUG_COMPONENT
  Component::_setComponentsDebugInfo();
#endif
  Component::deleteZombieComponents();
}

void SparAIContainer::onStartProcess()
{
#ifdef _DEBUG_COMPONENT
  Component::_setComponentsDebugInfo();
#endif
}

void SparAIContainer::onEndProcess()
{
#ifdef _DEBUG_COMPONENT
  Component::_setComponentsDebugInfo();
#endif
}