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

This file contains declarations for the scenario flightplan data structure.
The code takes care of parsing flight plans from file, representing
them as lists of actions.
*/
#pragma once

#include <optional>
#include <set>
#include <string>
#include <unordered_map>

#include "body.hpp"
#include "flightplanaction.hpp"
#include "scenariolib.hpp"
#include "vector.hpp"

namespace sim {

// TODO: rename this as Ship
struct FlightPlan {

    Body body;

    std::vector<std::shared_ptr<FlightPlanAction>> plan;

    // TODO: How to handle landed state and landed position in initial
    // conditions

    typedef std::string sst;

    bool set_key_value(std::optional<KeyValue> kv)
    {
        std::unordered_map<sst, std::function<void(sst)>> keyword_map{

            { "name", [=](sst v) { body.name                = v; } },
            { "max-acceleration", [=](sst v) { body.max_acc = stof(v); } },
            { "max-fuel", [=](sst v) { body.max_fuel        = stof(v); } },
            { "fuel-cons-rate", [=](sst v) { body.fuel_cons = stof(v); } },

            { "flight-state", [=](sst v) { body.flight_state = FALLING; } },
            // TODO: handle landed state
            { "position", [=](sst v) { body.pos              = stoV(v); } },
            { "velocity", [=](sst v) { body.vel              = stoV(v); } },
            { "attitude", [=](sst v) { body.att              = stoV(v); } },
            //
            { "fuel", [=](sst v) { body.fuel                 = stof(v); } },
            { "acc", [=](sst v) { body.acc                   = stof(v); } },

        };

        if (keyword_map.count(kv->key)) {
            keyword_map[kv->key](kv->value);
            return true;
        } else {
            return false;
        }
    };
};

bool        operator==(const FlightPlan& a, const FlightPlan& b);
inline bool operator!=(const FlightPlan& a, const FlightPlan& b)
{
    return !(a == b);
}<commit_msg>Implement way to run Ship state initialization at start of sim<commit_after>/*
This file is part of Groho, a simulator for inter-planetary travel and warfare.
Copyright (c) 2017-2018 by <NAME>. Some rights reserved, see LICENSE

This file contains declarations for the scenario flightplan data structure.
The code takes care of parsing flight plans from file, representing
them as lists of actions.
*/
#pragma once

#include <cmath>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>

#include "body.hpp"
#include "flightplanaction.hpp"
#include "scenariolib.hpp"
#include "vector.hpp"

namespace sim {

// TODO: rename this as Ship
struct FlightPlan {

    Body body;

    std::vector<std::shared_ptr<FlightPlanAction>> plan;

    // Initialization data that requires world state and can only be done
    // once we start running the simulator
    std::string initial_orbit;

    // TODO: How to handle landed state and landed position in initial
    // conditions

    typedef std::string sst;

    bool set_key_value(std::optional<KeyValue> kv)
    {
        std::unordered_map<sst, std::function<void(sst)>> keyword_map{

            { "name", [=](sst v) { body.name                = v; } },
            { "max-acceleration", [=](sst v) { body.max_acc = stof(v); } },
            { "max-fuel", [=](sst v) { body.max_fuel        = stof(v); } },
            { "fuel-cons-rate", [=](sst v) { body.fuel_cons = stof(v); } },
            { "orbiting", [=](sst v) { initial_orbit        = v; } },

            { "flight-state", [=](sst v) { body.flight_state = FALLING; } },
            // TODO: handle landed state
            { "position", [=](sst v) { body.pos              = stoV(v); } },
            { "velocity", [=](sst v) { body.vel              = stoV(v); } },
            { "attitude", [=](sst v) { body.att              = stoV(v); } },
            //
            { "fuel", [=](sst v) { body.fuel                 = stof(v); } },
            { "acc", [=](sst v) { body.acc                   = stof(v); } },

        };

        if (keyword_map.count(kv->key)) {
            keyword_map[kv->key](kv->value);
            return true;
        } else {
            return false;
        }
    };

    // Any initialization that requires actual world state and can only be done
    // after we start running the simulator.
    // This expects the Orrery to be computed with velocities
    void init(const WorldState& ws)
    {
        if (initial_orbit.length() > 0) {
            set_initial_state_as_orbiting(ws);
        }
    }

    void set_initial_state_as_orbiting(const WorldState& ws);
};

bool        operator==(const FlightPlan& a, const FlightPlan& b);
inline bool operator!=(const FlightPlan& a, const FlightPlan& b)
{
    return !(a == b);
}
{'fraction_non_alphanumeric': 0.14499283227524062, 'fraction_numerical': 0.003481466311693631, 'mean_word_length': 2.2110453648915187, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 31, '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': '2105569', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1504, 'n_words': 439}