#ifndef _HPP_KUNGFLOW_CHARACTER_AICONTROLLER
#define _HPP_KUNGFLOW_CHARACTER_AICONTROLLER

#include "../character_controller.hpp"

#include <boost/signals2.hpp>

class KungFlowGame;
class PlayState;
class Stage;
class CharacterModelView;
class Character;
class StageEntity;

struct PassRequest {
  PassRequest() {
    active = false;
    requester = nullptr;
    subject = nullptr;
    elapsedTime_ms = 0;
  }
  bool active;
  //const CharacterController *requester;
  const Character *requester;
  StageEntity *subject;
  unsigned long elapsedTime_ms;
};

class CharacterAIController : public CharacterController {

  public:

    CharacterAIController(const KungFlowGame *game, const PlayState *playState, const Character *character);
    virtual ~CharacterAIController();

    virtual void OnStepPhysicsTime(CharacterModelView *characterModelView);

    void RequestPass(const Character *requester, StageEntity *subject) {
      this->passRequest.active = true;
      this->passRequest.requester = requester;
      this->passRequest.subject = subject;
    }

  protected:

    const Character *character;

    Character *closestOpponent;
    Character *assignedOpponent;
    std::vector<Character*> closestOpponents;
    std::vector<Character*> closestMates;

    float randomSeed;

    // cache
    void UpdateCaches();
    unsigned int timeSinceLastUpdate_ms;
    unsigned int updateInterval_ms;
    // cached stuff:
    int nthClosestToAssignedOpponent;
    std::vector<Character*> assignedOpponents;

    void ResetPassRequest() {
      passRequest.active = false;
      passRequest.elapsedTime_ms = 0;
    }

    PassRequest passRequest;

  private:

    boost::signals2::connection personnelChangeConnection;

};

#endif
