<commit_before>/*
 * Copyright (c) 2013 <NAME> (<EMAIL>)
 *
 * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
 * or copy at http://opensource.org/licenses/MIT)
 */

#include <iostream>
#include <string>
#include <vector>

#include <boost/format.hpp>

#include "base_pokemon_impl.hpp"
#include <pkmnsim/enums.hpp>
#include <pkmnsim/paths.hpp>
#include <pkmnsim/database/queries.hpp>

#include "SQLiteCpp/src/SQLiteC++.h"

#include "base_pokemon_impl.hpp"
#include "base_pokemon_gen1impl.hpp"
#include "base_pokemon_gen2impl.hpp"
#include "base_pokemon_modernimpl.hpp"

using namespace std;

namespace pkmnsim
{
    base_pokemon::sptr base_pokemon::make(unsigned int id, unsigned int game)
    {
        try
        {
            //Get generation from game enum
            int gen = database::get_generation(game);

            if(gen < 1 or gen > 5) throw runtime_error("Gen must be 1-5.");

            switch(gen)
            {
                case 1:
                    return sptr(new base_pokemon_gen1impl(id, game));

                case 2:
                    return sptr(new base_pokemon_gen2impl(id, game));

                default:
                    return sptr(new base_pokemon_modernimpl(id, game));
            }
        }
        catch(const exception &e)
        {
            cerr << "Caught exception: " << e.what() << endl;
            exit(EXIT_FAILURE);
        }
    }

    base_pokemon_impl::base_pokemon_impl(unsigned int id, unsigned int game): base_pokemon()
    {
        switch(id)
        {
            case Species::NONE: //None
                from_game = game;
                pokemon_id = Species::NONE;
                species_id = Species::NONE;
                form_id = 0;
                pokemon_id = 0;
                species_id = 0;
                type1_id = 0;
                type2_id = 0;
                hp = 0;
                attack = 0;
                defense = 0;
                speed = 0;
                special = 0;
                special_attack = 0;
                special_defense = 0;
                break;

            case Species::INVALID: //Invalid
                from_game = game;
                pokemon_id = Species::INVALID;
                species_id = Species::INVALID;
                form_id = 0;
                pokemon_id = 0;
                species_id = 0;
                type1_id = 0;
                type2_id = 0;
                hp = 0;
                attack = 0;
                defense = 0;
                speed = 0;
                special = 0;
                special_attack = 0;
                special_defense = 0;
                break;

            default:
                from_game = game;
                species_id = id;
                
                SQLite::Database db(get_database_path().c_str());
                string query_string;
                
                //Get generation and name from specified game enum
                query_string = "SELECT version_group_id FROM versions WHERE id=" + to_string(game);
                int version_group_id = db.execAndGet(query_string.c_str());
                query_string = "SELECT generation_id FROM version_groups WHERE id=" + to_string(version_group_id);
                from_gen = int(db.execAndGet(query_string.c_str()));
                query_string = "SELECT name FROM version_names WHERE version_id=" + to_string(game);
                game_string = string((const char*)db.execAndGet(query_string.c_str()));
                
                //Fail if Pokemon's generation_id > specified gen
                query_string = "SELECT generation_id FROM pokemon_species WHERE id=" + to_string(id);
                unsigned int gen_id = int(db.execAndGet(query_string.c_str()));
                if(gen_id > from_gen)
                {
                    string error_message = database::get_species_name(from_gen) + ".";
                    throw runtime_error(error_message.c_str());
                }

                //Get Pokemon ID from database
                query_string = "SELECT id FROM pokemon WHERE species_id=" + to_string(species_id);
                pokemon_id = int(db.execAndGet(query_string.c_str()));
                
                //Even though most attributes are queried from the database when called, stats take a long time when
                //doing a lot at once, so grab these upon instantiation
                query_string = "SELECT base_stat FROM pokemon_stats WHERE pokemon_id=" + to_string(pokemon_id) +
                               " AND stat_id IN (1,2,3,6)";
            SQLite::Statement stats_query(db, query_string.c_str());

            stats_query.executeStep();
            hp = int(stats_query.getColumn(0));
            stats_query.executeStep();
            attack = int(stats_query.getColumn(0));
            stats_query.executeStep();
            defense = int(stats_query.getColumn(0));
            stats_query.executeStep();
            speed = int(stats_query.getColumn(0));
        }
    }

    unsigned int base_pokemon_impl::get_pokedex_num() const {return species_id;}
    string base_pokemon_impl::get_pokedex_entry() const {return database::get_pokedex_entry(species_id, from_game);}<commit_msg>base_pokemon: initialize type ID's in base_pokemon_impl constructor<commit_after>/*
 * Copyright (c) 2013 <NAME> (<EMAIL>)
 *
 * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
 * or copy at http://opensource.org/licenses/MIT)
 */

#include <iostream>
#include <string>
#include <vector>

#include <boost/format.hpp>

#include "base_pokemon_impl.hpp"
#include <pkmnsim/enums.hpp>
#include <pkmnsim/paths.hpp>
#include <pkmnsim/database/queries.hpp>

#include "SQLiteCpp/src/SQLiteC++.h"

#include "base_pokemon_impl.hpp"
#include "base_pokemon_gen1impl.hpp"
#include "base_pokemon_gen2impl.hpp"
#include "base_pokemon_modernimpl.hpp"

using namespace std;

namespace pkmnsim
{
    base_pokemon::sptr base_pokemon::make(unsigned int id, unsigned int game)
    {
        try
        {
            //Get generation from game enum
            int gen = database::get_generation(game);

            if(gen < 1 or gen > 5) throw runtime_error("Gen must be 1-5.");

            switch(gen)
            {
                case 1:
                    return sptr(new base_pokemon_gen1impl(id, game));

                case 2:
                    return sptr(new base_pokemon_gen2impl(id, game));

                default:
                    return sptr(new base_pokemon_modernimpl(id, game));
            }
        }
        catch(const exception &e)
        {
            cerr << "Caught exception: " << e.what() << endl;
            exit(EXIT_FAILURE);
        }
    }

    base_pokemon_impl::base_pokemon_impl(unsigned int id, unsigned int game): base_pokemon()
    {
        switch(id)
        {
            case Species::NONE: //None
                from_game = game;
                pokemon_id = Species::NONE;
                species_id = Species::NONE;
                form_id = 0;
                pokemon_id = 0;
                species_id = 0;
                type1_id = 0;
                type2_id = 0;
                hp = 0;
                attack = 0;
                defense = 0;
                speed = 0;
                special = 0;
                special_attack = 0;
                special_defense = 0;
                break;

            case Species::INVALID: //Invalid
                from_game = game;
                pokemon_id = Species::INVALID;
                species_id = Species::INVALID;
                form_id = 0;
                pokemon_id = 0;
                species_id = 0;
                type1_id = 0;
                type2_id = 0;
                hp = 0;
                attack = 0;
                defense = 0;
                speed = 0;
                special = 0;
                special_attack = 0;
                special_defense = 0;
                break;

            default:
                from_game = game;
                species_id = id;
                
                SQLite::Database db(get_database_path().c_str());
                string query_string;
                
                //Get generation and name from specified game enum
                query_string = "SELECT version_group_id FROM versions WHERE id=" + to_string(game);
                int version_group_id = db.execAndGet(query_string.c_str());
                query_string = "SELECT generation_id FROM version_groups WHERE id=" + to_string(version_group_id);
                from_gen = int(db.execAndGet(query_string.c_str()));
                query_string = "SELECT name FROM version_names WHERE version_id=" + to_string(game);
                game_string = string((const char*)db.execAndGet(query_string.c_str()));
                
                //Fail if Pokemon's generation_id > specified gen
                query_string = "SELECT generation_id FROM pokemon_species WHERE id=" + to_string(id);
                unsigned int gen_id = int(db.execAndGet(query_string.c_str()));
                if(gen_id > from_gen)
                {
                    string error_message = database::get_species_name(from_gen) + ".";
                    throw runtime_error(error_message.c_str());
                }

                //Get Pokemon ID from database
                query_string = "SELECT id FROM pokemon WHERE species_id=" + to_string(species_id);
                pokemon_id = int(db.execAndGet(query_string.c_str()));
                
                //Even though most attributes are queried from the database when called, stats take a long time when
                //doing a lot at once, so grab these upon instantiation
                query_string = "SELECT base_stat FROM pokemon_stats WHERE pokemon_id=" + to_string(pokemon_id) +
                               " AND stat_id IN (1,2,3,6)";
            SQLite::Statement stats_query(db, query_string.c_str());

            stats_query.executeStep();
            hp = int(stats_query.getColumn(0));
            stats_query.executeStep();
            attack = int(stats_query.getColumn(0));
            stats_query.executeStep();
            defense = int(stats_query.getColumn(0));
            stats_query.executeStep();
            speed = int(stats_query.getColumn(0));
            
            query_string = "SELECT type_id FROM pokemon_types WHERE slot=1 and pokemon_id=" + to_string(pokemon_id);
            type1_id = int(db.execAndGet(query_string.c_str()));
            
            //If there's only one type, this won't return anything
            query_string = "SELECT type_id FROM pokemon_types WHERE slot=2 and pokemon_id=" + to_string(pokemon_id);
            SQLite::Statement query(db, query_string.c_str());
            type2_id = (query.executeStep()) ? int(query.getColumn(0)) : Types::NONE;
        }
    }

    unsigned int base_pokemon_impl::get_pokedex_num() const {return species_id;}
    string base_pokemon_impl::get_pokedex_entry() const {return database::get_pokedex_entry(species_id, from_game);}
{'fraction_non_alphanumeric': 0.09383740864386898, 'fraction_numerical': 0.00947396914192908, 'mean_word_length': 1.6915978630403108, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1748408', 'n_tokens_mistral': 3316, 'n_tokens_neox': 3063, 'n_words': 713}