//
// Created by Dan Crosby on 3/14/20.
//

#include "DefensiveAmbushAction.hpp"

#include <utility>

#include "src/main/cpp/net/eagle0/shardok/library/util/CombatUtils.hpp"

namespace shardok {
auto DefensiveAmbushAction::InternalExecute(
        const GameStateW& currentState,
        const std::shared_ptr<RandomGenerator>& generator) const -> vector<ActionResult> {
    const auto results = CombatUtils::InternalPerformMelee(
            ActionCost(ActionCost::standard, 0),
            currentState->units()->Get(ambusherId),
            currentState->units()->Get(moverId),
            MakeHexMapTerrain(net::eagle0::shardok::storage::fb::Terrain_::Type_STILL_WATER),
            AttackOrientation::rear,
            ambusherRoll,
            0.0,
            /*isCharge=*/false,
            /*isAmbush=*/true,
            settings);

    return std::vector<ActionResult>{CombatUtils::MeleeAmbushResult(results)};
}

DefensiveAmbushAction::DefensiveAmbushAction(
        const UnitId ambusherId,
        const UnitId moverId,
        const double ambusherRoll,
        const SettingsGetter& settings)
    : ambusherId(ambusherId),
      moverId(moverId),
      ambusherRoll(ambusherRoll),
      settings(settings) {}
}  // namespace shardok