//
// Created by bastian on 29.03.22.
//

#include "RandomFailure.h"

BT::NodeStatus BT::RandomFailure::tick() {
    double failureChance;
    if (!getInput<double>("failure_chance", failureChance)) {
        std::cout << "could not get failure chance." << std::endl;
        return NodeStatus::FAILURE;
    }
    auto threshold = dist(re);
    if (threshold < failureChance) {
        return BT::NodeStatus::FAILURE;
    } else {
        return BT::NodeStatus::SUCCESS;
    }
}

BT::PortsList BT::RandomFailure::providedPorts() {
    return {InputPort<double>("failure_chance", "Chance to fail from 0 to 1")};
}

BT::RandomFailure::RandomFailure(
        const std::string &name, const BT::NodeConfiguration &config
) : SyncActionNode(name,config) {}
