//
// Created by Dan Crosby on 3/8/21.
//

#include "UndeadChangeActionFactory.hpp"

#include "src/main/cpp/net/eagle0/shardok/library/actions/UndeadChangeAction.hpp"
#include "src/main/flatbuffer/net/eagle0/shardok/storage/unit.hpp"

namespace shardok {

using Unit = net::eagle0::shardok::storage::fb::Unit;

auto UndeadChangeActionFactory::MakeUndeadChangeAction(const GameStateW& gameState) const
        -> ActionSPtr {
    vector<UnitId> undeadUnitIds{};
    for (const auto& unit : *gameState->units()) {
        if (unit->battalion().type() == net::eagle0::shardok::storage::fb::BattalionTypeId_UNDEAD &&
            unit->status() == net::eagle0::shardok::storage::fb::UnitStatus_NORMAL_UNIT) {
            undeadUnitIds.push_back(unit->unit_id());
        }
    }
    return std::make_shared<UndeadChangeAction>(
            undeadUnitIds,
            gameState->dead_count(),
            gameState->dead_armament(),
            settings.Backing().undead_decay_rate(),
            settings.Backing().undead_decay_floor(),
            settings.Backing().dead_reinforce_rate(),
            settings.GetBattalionType(net::eagle0::shardok::storage::fb::BattalionTypeId_UNDEAD)
                    ->capacity);
}

}  // namespace shardok