#ifndef ELEMENT_MEMBRANE_H
#define ELEMENT_MEMBRANE_H

#include "Element.h"

namespace MFM {

  #define DRUG_MISSILE_VERSION 1

  template <class CC>
  class Element_Membrane : public Element<CC>
  {
    // Extract short names for parameter types
    typedef typename CC::ATOM_TYPE T;
    typedef typename CC::PARAM_CONFIG P;
    enum { R = P::EVENT_WINDOW_RADIUS };
    enum { BITS = P::BITS_PER_ATOM,
	   LOC_X_POS = P3Atom<P>::P3_STATE_BITS_POS,
	   LOC_X_LEN = 8,

	   LOC_Y_POS = LOC_X_POS + LOC_X_LEN,
	   LOC_Y_LEN = 8

    };

    typedef BitField<BitVector<BITS>, LOC_X_LEN, LOC_X_POS> AFLocX;
    typedef BitField<BitVector<BITS>, LOC_Y_LEN, LOC_Y_POS> AFLocY;

    s32 GetLocX(const T& us) const
    {
      return AFLocX::Read(this->GetBits(us));
    }

    void SetLocX(T& us, const s32 age) const
    {
      AFLocX::Write(this->GetBits(us), age);
    }

    s32 GetLocY(const T& us) const
    {
      return AFLocY::Read(this->GetBits(us));
    }

    void SetLocY(T& us, const s32 age) const
    {
      AFLocY::Write(this->GetBits(us), age);
    }


  public:

    static Element_Membrane THE_INSTANCE;

    Element_Membrane()
      : Element<CC>(MFM_UUID_FOR("Membrane", DRUG_MISSILE_VERSION))
    {
      Element<CC>::SetAtomicSymbol("Mb");
      Element<CC>::SetName("Membrane");
    }

    virtual u32 PercentMovable(const T& you,
                               const T& me, const SPoint& offset) const
    {
      return 0;
    }

    virtual u32 DefaultPhysicsColor() const
    {
      return 0xff00ff00;
    }

    virtual u32 DefaultLowlightColor() const
    {
      return 0xff007f00;
    }

    virtual const char* GetDescription() const
    {
      return "Short for \"Dynamic Regulator\", This Atom controls the density of "
             "nearby Atoms by creating RES atoms and deleting nearby atoms.";
    }

    virtual void Behavior(EventWindow<CC>& window) const;
  };

  template <class CC>
  Element_Membrane<CC> Element_Membrane<CC>::THE_INSTANCE;


}

#include "Element_Membrane.tcc"

#endif //ELEMENT_MEMBRANE_H

