#ifndef _DealToSelf_
#define _DealToSelf_

#include "Events/LocomotionEvent.h"
#include "Behaviors/Nodes/MotionSequenceNode.h"
#include "Behaviors/Nodes/WalkNode.h"
#include "Motion/HeadPointerMC.h"
#include "Motion/WalkMC.h"
#include "Motion/MMAccessor.h"
#include "Shared/WorldState.h"
#include "Neutral.h"

#include "Motion/WalkMC.h"

#include "DualCoding/DualCoding.h"
using namespace DualCoding;

class DealToSelf : public VisualRoutinesStateNode {
 public:
  DealToSelf() : VisualRoutinesStateNode("WalkToTarget"),
	  walk_mc(), walk_id(MotionManager::invalid_MC_ID){}

  void DoStart() {
    VisualRoutinesStateNode::DoStart();
    cout << "Deal to Self starting up." << endl;
	 SharedObject<MediumMotionSequenceMC> mseq_mc;
	 mseq_mc->LoadFile("neutHead.mot");
	 motman->addPrunableMotion(mseq_mc);
    walk_id = motman->addPersistentMotion(walk_mc);
	 erouter->addTimer(this, 1000, 15000, false);
	 MMAccessor<WalkMC>(walk_id)->setTargetDisplacement(0, 0, 2.5, 39);
  }

  void processEvent(const EventBase& event) {
	  cout<<"dealToSelf process event called\n";

	  if(event.getSourceID() == 1000){
		  erouter->addTimer(this, 1001, 4500, false);
		  MMAccessor<WalkMC>(walk_id)->setTargetVelocity(80, 0, 0, 7);
	  }
	  else if(event.getSourceID() == 1001){
		  SharedObject<MediumMotionSequenceMC> mseq_mc1;
		  mseq_mc1->LoadFile("dropCard.mot");
		  motman->addPrunableMotion(mseq_mc1);
		  erouter->addTimer(this, 1002, 3500, false);
	  }
	  else if(event.getSourceID() == 1002){
		  cout<<"third sequence\n";
		  erouter->addTimer(this, 1003, 7000, false);
		  MMAccessor<WalkMC>(walk_id)->setTargetVelocity(-80, 0, 0, 17);
	  }
	  else if(event.getSourceID()==1003){
		  cout<<"fourth sequence\n";
		  MMAccessor<WalkMC>(walk_id)->setTargetDisplacement(0, 0, -2.3, 37);
		  erouter->addTimer(this, 1004, 13000, false);
	  }
	  else if(event.getSourceID() == 1004){
		  cout<<"fifth sequence\n";
		  MMAccessor<WalkMC>(walk_id)->setTargetVelocity(-80, 0, 0, 6);
		  erouter->addTimer(this, 1005, 4000, false);
	  }
	  else if(event.getSourceID() == 1005){
		  motman->removeMotion(walk_id);
		  Neutral *rtn = new Neutral();
		  rtn->DoStart();
		  erouter->addTimer(this, 1006, 25000, false);
	  }
	  else if(event.getSourceID() == 1006){
		  cout<<"deal to self completion posted.\n";
		  postCompletionEvent();
	  }
  }
  

  void DoStop() {
	  motman->removeMotion(walk_id);
    cout << "Deal To Self stopped." << endl;
    VisualRoutinesStateNode::DoStop();
  }


 private:
  SharedObject<WalkMC> walk_mc;
  MotionManager::MC_ID walk_id;

  DealToSelf(const DealToSelf&);
  DealToSelf& operator=(const DealToSelf&);
};

#endif

