//
//  FireOutActionFactory.cpp
//  eagle0_engine
//
//  Created by Dan Crosby on 1/6/19.
//  Copyright © 2019 none. All rights reserved.
//

#include "FireOutActionFactory.hpp"

#include "src/main/cpp/net/eagle0/shardok/library/FireUtils.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/actions/FireOutAction.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/util/HexMapUtils.hpp"

namespace shardok {
FireOutActionFactory::FireOutActionFactory(const SettingsGetter &getter) : settings(getter) {}

auto FireOutActionFactory::MakeFireOutAction(
        const Coords &coords,
        const Terrain *terrain,
        const WeatherFb *weather) const -> ActionSPtr {
    const int16_t base = settings.Backing().fire_out_naturally_base_odds();

    const int16_t terrainFactor = -PropensityByTerrain(terrain, settings);
    const int16_t weatherFactor =
            -settings.GetFirePropensityByWeatherConditions(weather->conditions());
    const int16_t windFactor = -weather->wind().speed_in_mph() *
                               settings.Backing().fire_propensity_wind_speed_multiplier();

    auto odds = MakeOdds(base, terrainFactor, weatherFactor, windFactor, 0);

    return std::make_shared<FireOutAction>(coords, terrain->modifier(), odds);
}

auto FireOutActionFactory::MakeFireOutActions(const HexMap *hexMap, const WeatherFb *weather) const
        -> ActionList {
    ActionList fireOutActions;

    for (const Coords &coords : GetAllCoords(hexMap)) {
        const auto *terrain = GetTerrain(hexMap, coords);
        if (terrain->modifier().fire().present()) {
            fireOutActions.push_back(MakeFireOutAction(coords, terrain, weather));
        }
    }

    return fireOutActions;
}
}  // namespace shardok
