#include <iostream>
#include <fstream>

#include "cc3k.h"
#include "arguments.h"
#include "constants.h"

int main(int argc, char **argv) {
        std::unique_ptr<cursor>  curse;
        std::unique_ptr<input>   in;
        std::unique_ptr<output> out;
        std::unique_ptr<RNG>     rng;
        std::ifstream data;

        feature enabled_features = proc_args(argc, argv, curse, in, out, rng, data);

        if (enabled_features &
            (FEATURE_PANIC | FEATURE_PANIC_FILE |
             FEATURE_CONFLICT | FEATURE_PANIC_SEED)) {
                panic_args(enabled_features);
                return RETURN_PANICKED;
        } else if (enabled_features &
                   (FEATURE_LIST_ARGS | FEATURE_LIST_COMMANDS |
                    FEATURE_LIST_ENEMIES | FEATURE_LIST_POTIONS |
                    FEATURE_LIST_RACES)) {
                print_list(enabled_features);
                return RETURN_FINE;
        }

        CC3K game_proc(enabled_features, in.get(), out.get(), rng.get(), data);

        while (true) {
                if (game_proc.run() == game_status::TERMINATED)
                        break;

                if (enabled_features & FEATURE_IN_FILE)
                        getchar();
        }

        return RETURN_FINE;
}
