#pragma once
#include <BWAPI.h>
#include <cassert>
#include <functional>
#include <set>

class UnitRecord;
template <typename T> class InfluenceMap;

static const int NB_NEXT_FRAMES_THREAT = 5;

// TODO: Future threat should be indexed by time instead of aggregated, i.e. threat(t)

/**
 * @brief Structure that holds threat information about a player at a certain position on the map.
 */
struct Threat
{
  // Current (possibly estimated) influence only
  double ground;
  double air;

  // Aggregation of future influence over NB_NEXT_FRAMES_THREAT frames.
  double futureGround;
  double futureAir;

  Threat() { reset(); }
  void reset() { ground = air = futureGround = futureAir = 0; }

  bool isNull() const {  return ground == 0 && air == 0 && futureGround == 0 && futureAir == 0; }

  void display(int x, int y, int w, int h, BWAPI::Player* player) const;

  static void update(InfluenceMap<Threat>& map);

  static const char* name() { return "Threat"; }

private:

  template <class Iterator>
  static void update(InfluenceMap<Threat>& map, Iterator begin, Iterator end)
  {
    for (; begin != end; ++begin)
    {
      update(map, *begin);
    }
  }

  static void update(InfluenceMap<Threat>& map, const UnitRecord* unit);
  struct UnitAttackInfo;
};