#include "Enemy.hpp"

const bool Tanks::Enemy::heroIsVisible() const {
  return timer <= 0 && Walker::heroIsVisible();
}

const bool Tanks::Enemy::getIsLeftTurn() const {
  return heroIsVisible() ? Walker::getIsLeftTurn() : to != nullptr && isLeft(*to);
}

const bool Tanks::Enemy::keepWalking() const {
  return !heroIsVisible();
}

Object& Tanks::Enemy::onFire() {
  if (++count > 2) {
    count = 0;
    timer = 3 * (
      1 + Math::rand() * getFireMistake()
    );
  }
  return Walker::onFire();
}

Object& Tanks::Enemy::simulate(
  const EnemyAction action,
  const Object::Time dt
) {
  if (from != nullptr && to != nullptr) {
    if (
      timer && (timer -= dt) <= 0
    ) {
      timer = 0;
    }
  }
  return Walker::simulate(
    action,
    dt
  );
}

const double Tanks::Enemy::getFireStartSpeed() const {
  return Walker::getFireStartSpeed() * Math::rand(0.5);
}
