#pragma once
#include "PatrolBaseBehavior.h"

/**
 * @brief Transition action returning the next checkpoint, possibly past-the-end of the checkpoints list if the
 *        patrol has finished.
 */
class NextCheckpoint : public TransitionAction
{
public:
  NextCheckpoint(std::list<BWAPI::Position>::const_iterator& currentCheckpoint, const std::list<BWAPI::Position>&)
    : m_currentCheckpoint(currentCheckpoint){}
  void start()
  {
    ++m_currentCheckpoint;
  }
protected:
  std::list<BWAPI::Position>::const_iterator& m_currentCheckpoint;
};

/**
 * @brief The FinitePatrolBehavior behavior instructs a group to patrol along a sequence of checkpoints, ending 
 *        the behavior when the loop is completed.
 */
class FinitePatrolBehavior : public PatrolBaseBehavior<NextCheckpoint>
{
public:
  FinitePatrolBehavior(const Process* parent, unsigned int initialPriority, const PersistentUnitGroup* patrollingGroup, std::list<BWAPI::Position>& checkPoints)
    : PatrolBaseBehavior<NextCheckpoint>(parent, initialPriority, patrollingGroup, checkPoints)
    , GroupBehavior(parent, initialPriority, patrollingGroup)
    , Behavior(parent, initialPriority)
    , FSM(parent)
    , Process(parent)
  {
  }
};
