/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef BePrimaryAttacker_h
#define BePrimaryAttacker_h

#include "../Motion/MotionInterface.h"
using namespace Motion;

#include "Behavior.h"
#include "BeLowLevel.h"
#include "../Main/RobotMain.h"
#include "state_machine.h"
#include "BehTree.h"

struct FeatureSet;

class BePrimaryAttacker : public IndependentBehavior {

public:
  static const int beh_id;
  static char const * const beh_name;
  
  static const int NumStates = 2;
  enum State { SELECT_BEH_SEQ,
	       RUN_BEH_SEQ};

  static char const * const state_names[NumStates];

  typedef FiniteStateMachine<State,ulong> FSM;

private:
  FSM fsm;

  MotionCommand out_command;
  const MotionCommand *playseq_cmd;

  EventManager *event_mgr;

  uint fs_id;
  EventProcessor *fs_ep;
  FeatureSet *fs;

  uint playseq_id;
  BehaviorSequence *playseq_ep;

  ulong circle_end_time;
  ulong wall_turn_end_time;
  ulong stand_scan_time;

  char* playseq;

  double calcActivation(FeatureSet *features);
  void createBehaviorTree(FeatureSet *features);
  void copyMotionCmd(MotionCommand *dest, const MotionCommand *source);
  char *chooseBehSeq(FeatureSet *features);

public:
  static EventProcessor *create() { return new BePrimaryAttacker; }

  BePrimaryAttacker();
  virtual ~BePrimaryAttacker();
  void reset(ulong timestamp);
  void sleep();

  double operator()(FeatureSet *features,
		    MotionCommand *command, bool goalie=false);

  virtual bool initConnections();
  virtual bool setupEventMgr();
  virtual bool update(ulong time,const EventList *events);
  virtual const MotionCommand *get(ulong time);

  uchar *encodeAllNames(ulong time,uchar *buf,int buf_size);
  uchar *encodeTrace(uchar *buf,int buf_size);
};

#endif
