<commit_before>/*
This file is part of Groho, a simulator for inter-planetary travel and warfare.
Copyright (c) 2018 by <NAME>. Some rights reserved, see LICENSE

Timed burn - set acceleration and the unset it after a predetermined time
*/

#include "flightplanaction.hpp"

namespace sim {

// TODO: What happens when burns are fractions of a time step?
struct BURN : public FlightPlanAction {

    double                acc;
    double                burn_duration;
    std::optional<double> burn_end_time;

    void setup(
        [[maybe_unused]] SnapShot<ShipLike>&                    this_ship,
        [[maybe_unused]] const Collection<SnapShotV<RockLike>>& system)
    {
        ;
    }

    ShipCommand execute(
        const SnapShot<ShipLike>&                               this_ship,
        [[maybe_unused]] const Collection<SnapShotV<RockLike>>& system)
    {
        if (burn_end_time) {
            if (*burn_end_time < this_ship.state.t_s) {
                return { acc, {}, {} };
            } else {
                done = true;
                return { 0, {}, {} };
            }
        } else {
            burn_end_time = this_ship.state.t_s + burn_duration;
            if (acc > this_ship.property.max_acc) {
                LOG_S(WARNING)
                    << line_no << ": SET_ACCEL for "
                    << this_ship.property.naif.name << " exceeds max_acc";
                acc = this_ship.property.max_acc;
            }
            return { acc, {}, {} };
        }
    }

    bool is_blocking() const { return false; }

    std::string usage() const
    {
        return R"(Fire engines for given time.
    
    acc:0.01 \ ; acceleration in km/s^2
    for:10  ; duration in s)";
    }
};

template <> std::unique_ptr<FlightPlanAction> construct<BURN>(params_t* params)
{
    auto action = std::unique_ptr<BURN>(new BURN());
    if (params) {
        action->acc           = stof((*params)["acc"]);
        action->burn_duration = stod((*params)["for"]);
    }
    return action;
}
}<commit_msg>docs: Remove extra space in "burn" help text<commit_after>/*
This file is part of Groho, a simulator for inter-planetary travel and warfare.
Copyright (c) 2018 by <NAME>. Some rights reserved, see LICENSE

Timed burn - set acceleration and the unset it after a predetermined time
*/

#include "flightplanaction.hpp"

namespace sim {

// TODO: What happens when burns are fractions of a time step?
struct BURN : public FlightPlanAction {

    double                acc;
    double                burn_duration;
    std::optional<double> burn_end_time;

    void setup(
        [[maybe_unused]] SnapShot<ShipLike>&                    this_ship,
        [[maybe_unused]] const Collection<SnapShotV<RockLike>>& system)
    {
        ;
    }

    ShipCommand execute(
        const SnapShot<ShipLike>&                               this_ship,
        [[maybe_unused]] const Collection<SnapShotV<RockLike>>& system)
    {
        if (burn_end_time) {
            if (*burn_end_time < this_ship.state.t_s) {
                return { acc, {}, {} };
            } else {
                done = true;
                return { 0, {}, {} };
            }
        } else {
            burn_end_time = this_ship.state.t_s + burn_duration;
            if (acc > this_ship.property.max_acc) {
                LOG_S(WARNING)
                    << line_no << ": SET_ACCEL for "
                    << this_ship.property.naif.name << " exceeds max_acc";
                acc = this_ship.property.max_acc;
            }
            return { acc, {}, {} };
        }
    }

    bool is_blocking() const { return false; }

    std::string usage() const
    {
        return R"(Fire engines for given time.
    acc:0.01 \ ; acceleration in km/s^2
    for:10  ; duration in s)";
    }
};

template <> std::unique_ptr<FlightPlanAction> construct<BURN>(params_t* params)
{
    auto action = std::unique_ptr<BURN>(new BURN());
    if (params) {
        action->acc           = stof((*params)["acc"]);
        action->burn_duration = stod((*params)["for"]);
    }
    return action;
}
}
{'fraction_non_alphanumeric': 0.11613691931540342, 'fraction_numerical': 0.0053789731051344745, 'mean_word_length': 1.8830162085976039, 'pattern_counts': {'":': 2, '<': 45, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1508671', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1195, 'n_words': 301}