示例#1
0
    void pokemon_box_gcnimpl::set_pokemon(
        int index,
        const pkmn::pokemon::sptr& new_pokemon
    )
    {
        int max_index = get_capacity();
        pkmn::enforce_bounds("Box index", index, 0, max_index);

        if(_pokemon_list.at(index)->get_native_pc_data() == new_pokemon->get_native_pc_data())
        {
            throw std::invalid_argument("Cannot set a Pokémon to itself.");
        }

        boost::lock_guard<pokemon_box_gcnimpl> lock(*this);

        // If the given Pokémon isn't from this box's game, convert it if we can.
        pkmn::pokemon::sptr actual_new_pokemon;
        if(_game_id == new_pokemon->get_database_entry().get_game_id())
        {
            actual_new_pokemon = new_pokemon;
        }
        else
        {
            actual_new_pokemon = new_pokemon->to_game(get_game());
        }

        // Make sure no one else is using the new Pokémon variable.
        pokemon_gcnimpl* p_new_pokemon = dynamic_cast<pokemon_gcnimpl*>(
                                             actual_new_pokemon.get()
                                         );
        BOOST_ASSERT(p_new_pokemon != nullptr);
        boost::lock_guard<pokemon_gcnimpl> new_pokemon_lock(*p_new_pokemon);

        // Copy the underlying memory to the party. At the end of this process,
        // all existing variables will correspond to the same Pokémon, even if
        // their underlying memory has changed.
        //
        // Note: as we control the implementation, we know the PC data points
        // to the whole Pokémon data structure.
        delete _libpkmgc_box_uptr->pkm[index];

        _libpkmgc_box_uptr->pkm[index] =
            static_cast<LibPkmGC::GC::Pokemon*>(
                actual_new_pokemon->get_native_pc_data()
            )->clone();
        _pokemon_list[index] = std::make_shared<pokemon_gcnimpl>(
                                   dynamic_cast<LibPkmGC::GC::Pokemon*>(
                                       _libpkmgc_box_uptr->pkm[index]
                                   ),
                                   _game_id
                               );
    }
示例#2
0
void pokemon_equality_check(pkmn::pokemon::sptr pkmn1, pkmn::pokemon::sptr pkmn2)
{
    BOOST_CHECK_EQUAL(pkmn1->get_species_id(), pkmn2->get_species_id());
    BOOST_CHECK_EQUAL(pkmn1->get_game_id(), pkmn2->get_game_id());

    if(pkmn1->get_species_id() == pkmn::Species::NONE)
        return;
    else if(pkmn1->get_species_id() == pkmn::Species::INVALID)
    {
        BOOST_CHECK(!memcmp(pkmn1->get_native(), pkmn2->get_native(), native_sizes[pkmn1->get_generation()]));
        return;
    }

    BOOST_CHECK_EQUAL(pkmn1->get_original_game_id(), pkmn2->get_original_game_id());
    BOOST_CHECK_EQUAL(pkmn1->get_pokemon_id(), pkmn2->get_pokemon_id());
    BOOST_CHECK_EQUAL(pkmn1->get_ability_id(), pkmn2->get_ability_id());
    BOOST_CHECK_EQUAL(pkmn1->get_item_id(), pkmn2->get_item_id());
    BOOST_CHECK_EQUAL(pkmn1->get_nature_id(), pkmn2->get_nature_id());
    BOOST_CHECK_EQUAL(pkmn1->get_form_id(), pkmn2->get_form_id());
    BOOST_CHECK(pkmn1->get_markings() == pkmn2->get_markings());
    BOOST_CHECK(pkmn1->get_ribbons().hoenn == pkmn2->get_ribbons().hoenn);
    BOOST_CHECK(pkmn1->get_ribbons().sinnoh.ribbons1 == pkmn2->get_ribbons().sinnoh.ribbons1);
    BOOST_CHECK(pkmn1->get_ribbons().sinnoh.ribbons2 == pkmn2->get_ribbons().sinnoh.ribbons2);
    BOOST_CHECK(pkmn1->get_ribbons().sinnoh.ribbons3 == pkmn2->get_ribbons().sinnoh.ribbons3);
    BOOST_CHECK(pkmn1->get_ribbons().unova == pkmn2->get_ribbons().unova);
    BOOST_CHECK(pkmn1->get_ribbons().kalos == pkmn2->get_ribbons().kalos);
    BOOST_CHECK(pkmn1->get_super_training_medals() == pkmn2->get_super_training_medals());
    BOOST_CHECK(pkmn1->get_pokerus() == pkmn2->get_pokerus());
    BOOST_CHECK(pkmn1->get_nickname() == pkmn2->get_nickname());
    BOOST_CHECK(pkmn1->get_trainer_name() == pkmn2->get_trainer_name());
    BOOST_CHECK(pkmn1->get_trainer_gender() == pkmn2->get_trainer_gender());
    BOOST_CHECK_EQUAL(pkmn1->get_trainer_id(), pkmn2->get_trainer_id());
    BOOST_CHECK(pkmn1->get_ball() == pkmn2->get_ball());
    BOOST_CHECK_EQUAL(pkmn1->get_met_level(), pkmn2->get_met_level());
    BOOST_CHECK_EQUAL(pkmn1->get_personality(), pkmn2->get_personality());
    BOOST_CHECK_EQUAL(pkmn1->get_friendship(), pkmn2->get_friendship());
    BOOST_CHECK_EQUAL(pkmn1->get_level(), pkmn2->get_level());
    BOOST_CHECK_EQUAL(pkmn1->get_experience(), pkmn2->get_experience());
    BOOST_CHECK(pkmn1->get_gender() == pkmn2->get_gender());
    BOOST_CHECK_EQUAL(pkmn1->is_shiny(), pkmn2->is_shiny());

    pkmn::dict<pkmn::pkstring, int> pkmn1_stats = pkmn1->get_stats();
    pkmn::dict<pkmn::pkstring, int> pkmn2_stats = pkmn2->get_stats();
    BOOST_CHECK_EQUAL(pkmn1_stats.at("HP"), pkmn2_stats.at("HP"));
    BOOST_CHECK_EQUAL(pkmn1_stats.at("Attack"), pkmn2_stats.at("Attack"));
    BOOST_CHECK_EQUAL(pkmn1_stats.at("Defense"), pkmn2_stats.at("Defense"));
    BOOST_CHECK_EQUAL(pkmn1_stats.at("Speed"), pkmn2_stats.at("Speed"));

    if(pkmn1->get_generation() == 1)
        BOOST_CHECK_EQUAL(pkmn1_stats.at("Special"), pkmn2_stats.at("Special"));
    else
    {
        BOOST_CHECK_EQUAL(pkmn1_stats.at("Special Attack"), pkmn2_stats.at("Special Attack"));
        BOOST_CHECK_EQUAL(pkmn1_stats.at("Special Defense"), pkmn2_stats.at("Special Defense"));
    }

    pkmn::dict<pkmn::pkstring, int> pkmn1_EVs = pkmn1->get_EVs();
    pkmn::dict<pkmn::pkstring, int> pkmn2_EVs = pkmn2->get_EVs();
    BOOST_CHECK_EQUAL(pkmn1_EVs.at("HP"), pkmn2_EVs.at("HP"));
    BOOST_CHECK_EQUAL(pkmn1_EVs.at("Attack"), pkmn2_EVs.at("Attack"));
    BOOST_CHECK_EQUAL(pkmn1_EVs.at("Defense"), pkmn2_EVs.at("Defense"));
    BOOST_CHECK_EQUAL(pkmn1_EVs.at("Speed"), pkmn2_EVs.at("Speed"));

    if(pkmn1->get_generation() < 3)
        BOOST_CHECK_EQUAL(pkmn1_EVs.at("Special"), pkmn2_EVs.at("Special"));
    else
    {
        BOOST_CHECK_EQUAL(pkmn1_EVs.at("Special Attack"), pkmn2_EVs.at("Special Attack"));
        BOOST_CHECK_EQUAL(pkmn1_EVs.at("Special Defense"), pkmn2_EVs.at("Special Defense"));
    }

    pkmn::dict<pkmn::pkstring, int> pkmn1_IVs = pkmn1->get_IVs();
    pkmn::dict<pkmn::pkstring, int> pkmn2_IVs = pkmn2->get_IVs();
    BOOST_CHECK_EQUAL(pkmn1_IVs.at("HP"), pkmn2_IVs.at("HP"));
    BOOST_CHECK_EQUAL(pkmn1_IVs.at("Attack"), pkmn2_IVs.at("Attack"));
    BOOST_CHECK_EQUAL(pkmn1_IVs.at("Defense"), pkmn2_IVs.at("Defense"));
    BOOST_CHECK_EQUAL(pkmn1_IVs.at("Speed"), pkmn2_IVs.at("Speed"));

    if(pkmn1->get_generation() < 3)
        BOOST_CHECK_EQUAL(pkmn1_IVs.at("Special"), pkmn2_IVs.at("Special"));
    else
    {
        BOOST_CHECK_EQUAL(pkmn1_IVs.at("Special Attack"), pkmn2_IVs.at("Special Attack"));
        BOOST_CHECK_EQUAL(pkmn1_IVs.at("Special Defense"), pkmn2_IVs.at("Special Defense"));
    }

    pkmn::moveset_t moves1, moves2;
    pkmn1->get_moves(moves1);
    pkmn2->get_moves(moves2);
    BOOST_CHECK(moves1[0].name == moves2[0].name);
    BOOST_CHECK(moves1[1].name == moves2[1].name);
    BOOST_CHECK(moves1[2].name == moves2[2].name);
    BOOST_CHECK(moves1[3].name == moves2[3].name);

    pkmn::dict<pkmn::pkstring, int> pkmn1_attributes = pkmn1->get_attributes();
    pkmn::dict<pkmn::pkstring, int> pkmn2_attributes = pkmn2->get_attributes();
    BOOST_CHECK_EQUAL(pkmn1_attributes.size(), pkmn2_attributes.size());
    BOOST_FOREACH(const pkmn::pkstring &key, pkmn1_attributes.keys())
    {
        BOOST_CHECK_EQUAL(pkmn1_attributes.at(key), pkmn1_attributes.at(key,(pkmn1_attributes.at(key)-1)));
    }
}
示例#3
0
文件: utils.cpp 项目: ncorgan/libpkmn
// Make sure parsing doesn't crash.
void read_all_pokemon_fields(const pkmn::pokemon::sptr& pokemon)
{
    std::string game = pokemon->get_game();
    int generation = game_generations.at(game);
    (void)generation;

    (void)pokemon->get_species();
    (void)pokemon->get_form();
    (void)pokemon->get_condition();
    (void)pokemon->get_nickname();
    (void)pokemon->get_original_trainer_name();
    (void)pokemon->get_experience();
    (void)pokemon->get_level();
    (void)pokemon->get_moves();
    (void)pokemon->get_EVs();
    (void)pokemon->get_IVs();
    (void)pokemon->get_current_hp();
    (void)pokemon->get_stats();
    (void)pokemon->get_icon_filepath();
    (void)pokemon->get_sprite_filepath();

    for(const std::string& attribute: pokemon->get_numeric_attribute_names())
    {
        (void)pokemon->get_numeric_attribute(attribute);
    }
    for(const std::string& attribute: pokemon->get_string_attribute_names())
    {
        (void)pokemon->get_string_attribute(attribute);
    }
    for(const std::string& attribute: pokemon->get_boolean_attribute_names())
    {
        (void)pokemon->get_boolean_attribute(attribute);
    }

    if(generation >= 2)
    {
        (void)pokemon->is_egg();
        (void)pokemon->get_gender();
        (void)pokemon->is_shiny();
        (void)pokemon->get_held_item();
        (void)pokemon->get_pokerus_duration();
        (void)pokemon->get_original_trainer_gender();
        (void)pokemon->get_current_trainer_friendship();
        (void)pokemon->get_level_met();
        (void)pokemon->get_location_met(false);
    }
    if(generation >= 3)
    {
        (void)pokemon->get_ability();
        (void)pokemon->get_ball();
        (void)pokemon->get_personality();
        (void)pokemon->get_markings();
        (void)pokemon->get_ribbons();
        (void)pokemon->get_contest_stats();
    }
    if(generation >= 4)
    {
        (void)pokemon->get_location_met(true);
    }
}