/* 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 Attacker_h
#define Attacker_h

#include "../Motion/MotionInterface.h"
using namespace Motion;

#include "BePrimaryAttacker.h"
#include "BeSupportingAttacker.h"
#include "BeLowLevel.h"
#include "Behavior.h"
#include "state_machine.h"

class Attacker : public IndependentBehavior {
 public:
  static const int beh_id;

  static char const * const beh_name;

  static const int NumStates = 2;
  enum State {PRIMARY_ATTACKER, SUPPORTING_ATTACKER};
  
  static char const * const state_names[NumStates];

  typedef FiniteStateMachine<State,ulong> FSM;

 private:
  FSM fsm;  
  MotionCommand out_command;

  BePrimaryAttacker *primary_attacker;
  BeSupportingAttacker *supporting_attacker;
  FeatureSet *fs;

  // the id of the FeatureSet event processor from the event system
  uint fs_id;

  void resetCommand(MotionCommand *command);
  
 public:

  static EventProcessor *create() { return new Attacker; }

  Attacker();
  virtual ~Attacker();

  void reset(ulong time);
  void sleep() {fsm.sleep(); primary_attacker->sleep(); supporting_attacker->sleep();}
  double operator()(FeatureSet *features,
		    MotionCommand *command);

  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
