#pragma once
#include "UnitRecord.h"

// Optimization for units which can't morph

class StaticUnitRecord : public UnitRecord
{
public:
  StaticUnitRecord(BWAPI::Unit* unit)
    : UnitRecord(unit)
  {
  }
};

template <class UnitRecordType>
class StaticUnitRecordT : public StaticUnitRecord
{
public:
  StaticUnitRecordT(BWAPI::Unit* unit)
    : StaticUnitRecord(unit)
    , m_staticUnitRecordType(this, unit->getType())
    , m_staticSavedState(&m_staticUnitRecordType)
  {
    m_staticUnitRecordType._markAsStatic();
    m_staticSavedState._markAsStatic();
    m_currentUnitRecordType = &m_staticUnitRecordType;
  }
  ~StaticUnitRecordT()
  {
    m_currentUnitRecordType = NULL;
    m_savedState = NULL;
  }

protected:
  virtual typename UnitRecordType::SavedState* saveState()
  {
    m_staticSavedState = typename UnitRecordType::SavedState(&m_staticUnitRecordType);
    return &m_staticSavedState;
  }

  UnitRecordType m_staticUnitRecordType;
  typename UnitRecordType::SavedState m_staticSavedState;
};