#ifndef _UNITINPUT_H_
#define _UNITINPUT_H_

#include "allegro.h"
#include "AddUnitTemplate.h"
#include "Round.h"

//covers AI for the unit
//arena to determine if it's out of bounds

struct aiUnitSort {

  aiUnitSort ()
  { unitToLookAt = NULL; hpCriterion = 0; }

  int sum ()
  { return (hpCriterion + distCriterion); }

  bool isLessThan (aiUnitSort b)
  { return (sum () < b.sum ()); }

  bool isEqualTo (aiUnitSort b)
  { return (sum () == b.sum ()); }

  Unit * unitToLookAt;
  int hpCriterion;
  int distCriterion;
};

class Unit;
class UnitList;

class UnitInput {
 public:
  UnitInput ();
  UnitInput (UnitInput *, int);
  void setCounters ();

  void decideAction (Unit * thisUnit, UnitList * units, Round * rnd);
  void locateTarget (Unit * thisUnit, UnitList * units);
  bool aimIt (Unit * thisUnit, Round * rnd);
  void moveIt (Unit *, bool);
  void attackP (Unit * thisUnit, int);
  void switchTargets (Unit * thisUnit, UnitList * units);
  Unit * prepAIUnitSort (Unit * thisUnit, vector <Unit *> *, vector <aiUnitSort *> *);
  static bool aiULess (aiUnitSort * a1, aiUnitSort * a2);
  static bool aiUEqual (aiUnitSort * a1, aiUnitSort * a2);

  ~UnitInput ();

  //behavior
  int targetAffiliation; //the affiliation of the target
  int targetPriorityHP;
  int targetPriorityDist;
  int switchTarget; //when should it switch targets?

  //if the unit should home in on a target by move forward -> correct angle
  int homeTimeInbetweenCorrection;
  fixed homeAngleCorrection; //how much should they correct by?

  //if the unit should periodically fire
  int attackPeriodIndex;

  fixed attackDistMin;
  fixed attackDistMax;
  fixed attackAngleSpread;

  bool careAboutArena;

 protected:
  fixed walkingDir;
  bool targetLocated;
  bool inAttackRange;
  Unit * targetUnit;
  int homeTimeInbetweenCorrectionCounter;
};

#endif
