/* * Copyright 2007-2008 Ben Boeckel * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ // Header include #include "MapTrainerTeamMember.h" // Pokemod includes #include "Item.h" #include "MapTrainer.h" #include "Pokemod.h" #include "Rules.h" #include "Species.h" #include "SpeciesMove.h" // Qt includes #include Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember) : Object("MapTrainerTeamMember", teamMember.parent(), teamMember.id()) { *this = teamMember; } Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainer* parent, const int id) : Object("MapTrainerTeamMember", parent, id), m_species(INT_MAX), m_level(INT_MAX) { } Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember, const MapTrainer* parent, const int id) : Object("MapTrainerTeamMember", parent, id) { *this = teamMember; } Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const QDomElement& xml, const MapTrainer* parent, const int id) : Object("MapTrainerTeamMember", parent, id) { load(xml, id); } void Pokemod::MapTrainerTeamMember::validate() { TEST(setSpecies, species); TEST(setLevel, level); if (static_cast(pokemod())->rules()->maxAbilities() < m_ability.size()) emit(error("Too many abilities")); TEST_LIST(setAbility, ability); if (static_cast(pokemod())->rules()->maxHeldItems() < m_item.size()) emit(error("Too many held items")); TEST_LIST(setItem, item); if (static_cast(pokemod())->rules()->maxMoves() < m_move.size()) emit(error("Too many moves")); TEST_LIST(setMove, move); if (static_cast(pokemod())->rules()->maxNatures() < m_nature.size()) emit(error("Too many natures")); TEST_LIST(setNature, nature); } void Pokemod::MapTrainerTeamMember::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(int, species); LOAD(int, level); LOAD_LIST(int, ability); LOAD_LIST(int, item); LOAD_LIST(int, move); LOAD_LIST(int, nature); } QDomElement Pokemod::MapTrainerTeamMember::save() const { SAVE_CREATE(); SAVE(int, species); SAVE(int, level); SAVE_LIST(int, ability); SAVE_LIST(int, item); SAVE_LIST(int, move); SAVE_LIST(int, nature); return xml; } void Pokemod::MapTrainerTeamMember::setSpecies(const int species) { if (static_cast(pokemod())->speciesIndex(species) == INT_MAX) { emit(error(bounds("species"))); return; } CHECK(species); } void Pokemod::MapTrainerTeamMember::setLevel(const int level) { if (static_cast(pokemod())->rules()->maxLevel() < level) { emit(error(bounds("level"))); return; } CHECK(level); } void Pokemod::MapTrainerTeamMember::setAbility(const int ability, const bool state) { if (static_cast(pokemod())->abilityIndex(ability) == INT_MAX) { emit(error(bounds("ability"))); return; } if (state && !m_ability.contains(ability)) { if (m_ability.size() < static_cast(pokemod())->rules()->maxAbilities()) { m_ability.append(ability); emit(changed()); } else emit(error("Cannot have any more abilities")); } else if (m_ability.contains(ability)) { m_ability.removeAll(ability); emit(changed()); } } void Pokemod::MapTrainerTeamMember::setItem(const int item, const bool state) { if (static_cast(pokemod())->itemIndex(item) == INT_MAX) { emit(error(bounds("item"))); return; } if (state && !m_item.contains(item)) { if (m_item.size() < static_cast(pokemod())->rules()->maxHeldItems()) { m_item.append(item); emit(changed()); } else emit(error("Cannot hold any more items")); } else if (m_item.contains(item)) { m_item.removeAll(item); emit(changed()); } } void Pokemod::MapTrainerTeamMember::setMove(const int move, const bool state) { if (static_cast(pokemod())->moveIndex(move) == INT_MAX) { emit(error(bounds("move"))); return; } if (state && !m_move.contains(move)) { const Species* species = static_cast(pokemod())->speciesById(move); for (int i = 0; i < species->moveCount(); ++i) { const SpeciesMove* speciesMove = species->move(i); if (speciesMove->move() == move) { if (m_move.size() < static_cast(pokemod())->rules()->maxMoves()) { m_move.append(move); emit(changed()); return; } else emit(error("Cannot know any more moves")); } } emit(error("Cannot learn the move")); } else if (m_move.contains(move)) { m_move.removeAll(move); emit(changed()); } } void Pokemod::MapTrainerTeamMember::setNature(const int nature, const bool state) { if (static_cast(pokemod())->natureIndex(nature) == INT_MAX) { emit(error(bounds("nature"))); return; } if (state && !m_nature.contains(nature)) { if (m_nature.size() < static_cast(pokemod())->rules()->maxNatures()) { m_nature.append(nature); emit(changed()); } else emit(error("Cannot have any more natures")); } else if (m_nature.contains(nature)) { m_nature.removeAll(nature); emit(changed()); } } int Pokemod::MapTrainerTeamMember::species() const { return m_species; } int Pokemod::MapTrainerTeamMember::level() const { return m_level; } bool Pokemod::MapTrainerTeamMember::ability(const int ability) const { return m_ability.contains(ability); } bool Pokemod::MapTrainerTeamMember::item(const int item) const { return m_item.contains(item); } bool Pokemod::MapTrainerTeamMember::move(const int move) const { return m_move.contains(move); } bool Pokemod::MapTrainerTeamMember::nature(const int nature) const { return m_nature.contains(nature); } Pokemod::MapTrainerTeamMember& Pokemod::MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs) { if (this == &rhs) return *this; COPY(species); COPY(level); COPY(ability); COPY(item); COPY(move); COPY(nature); return *this; }