#pragma once
#include "GroupDynamicLocation.h"

//Possiblement forward declarable à condition d'avoir un .cpp
#include "../Static/Shape/RectangularLocation.h"
#include "../../../Utils/PersistentUnitGroup.h"

/**
 * @brief Dynamic location representing a moving (expanded) rectangle providing a bounding box for a group of units.
 */
class GroupRectangularLocation : public GroupDynamicLocation
{
public:
  GroupRectangularLocation(const PersistentUnitGroup* group, int halfAdditionalLengthX, int halfAdditionalLengthY)
    : GroupDynamicLocation(group)
    , m_halfAdditionalLengthX(halfAdditionalLengthX)
    , m_halfAdditionalLengthY(halfAdditionalLengthY)
  {
  }

  GroupRectangularLocation(const PersistentUnitGroup* group)
    : GroupDynamicLocation(group)
    , m_halfAdditionalLengthX(DANGER_DISTANCE)
    , m_halfAdditionalLengthY(DANGER_DISTANCE)
  {
  }

  RectangularLocation getRectangularLocation() const
  {
    return RectangularLocation::getBoundingBox<PersistentUnitGroup>(*m_group);
  }

  RectangularLocation getExpandedRectangularLocation() const
  {
    return RectangularLocation::getBoundingBox<PersistentUnitGroup>(*m_group).expand(DANGER_DISTANCE, DANGER_DISTANCE);
  }

  virtual BWAPI::Position getCurrentCenter() const
  {
    return m_group->getCenter();
  }

  virtual bool isInLocation(BWAPI::Position position) const
  {
    if (m_group->size() == 0)
      return false;
    else
      return RectangularLocation::getBoundingBox<PersistentUnitGroup>(*m_group).expand(DANGER_DISTANCE, DANGER_DISTANCE).isInLocation(position);
  }

  virtual bool isInLocation(BWAPI::TilePosition tile) const
  {
    if (m_group->size() == 0)
      return false;
    else
      return RectangularLocation::getBoundingBox<PersistentUnitGroup>(*m_group).expand(DANGER_DISTANCE, DANGER_DISTANCE).isInLocation(tile);
  }

protected:
  virtual void _output(std::ostream& out) const
  {
    out << "Group rectangular location " << *m_group << " (" << m_halfAdditionalLengthX << ", " << m_halfAdditionalLengthY << ")";
  }

  const int m_halfAdditionalLengthX;
  const int m_halfAdditionalLengthY;
};