/* * 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" // Qt includes #include MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember) : Object("MapTrainerTeamMember", teamMember.parent(), teamMember.id()) { *this = teamMember; } MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainer* parent, const int id) : Object("MapTrainerTeamMember", parent, id), m_species(INT_MAX), m_level(INT_MAX), m_nature(INT_MAX) { } MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember, const MapTrainer* parent, const int id) : Object("MapTrainerTeamMember", parent, id) { *this = teamMember; } MapTrainerTeamMember::MapTrainerTeamMember(const QDomElement& xml, const MapTrainer* parent, const int id) : Object("MapTrainerTeamMember", parent, id) { load(xml, id); } void MapTrainerTeamMember::validate() { TEST(setSpecies, species); TEST(setLevel, level); if (m_item.size() <= static_cast(pokemod())->rules()->holdItems()) { TEST_LIST(setItem, item); } else emit(error("Too many held items")); if (static_cast(pokemod())->rules()->natureAllowed()) { TEST(setNature, nature); } } void MapTrainerTeamMember::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(int, species); LOAD(int, level); LOAD(int, nature); LOAD_LIST(int, item) } QDomElement MapTrainerTeamMember::save() const { SAVE_CREATE(); SAVE(int, species); SAVE(int, level); SAVE(int, nature); SAVE_LIST(int, item); return xml; } void MapTrainerTeamMember::setSpecies(const int species) { if (static_cast(pokemod())->speciesIndex(species) == INT_MAX) { emit(error(bounds("species"))); return; } m_species = species; emit(changed()); } void MapTrainerTeamMember::setLevel(const int level) { if (static_cast(pokemod())->rules()->maxLevel() < level) { emit(error(bounds("level"))); return; } m_level = level; emit(changed()); } void MapTrainerTeamMember::setItem(const int item, const bool state) { if (static_cast(pokemod())->itemIndex(item) == INT_MAX) { emit(error(bounds("item"))); return; } if (state) { if (!m_item.contains(item)) { m_item.append(item); emit(changed()); } } else { m_item.removeAll(item); emit(changed()); } } void MapTrainerTeamMember::setNature(const int nature) { if (!static_cast(pokemod())->rules()->natureAllowed() || (static_cast(pokemod())->natureIndex(nature) == INT_MAX)) { emit(error(bounds("nature"))); return; } m_nature = nature; emit(changed()); } int MapTrainerTeamMember::species() const { return m_species; } int MapTrainerTeamMember::level() const { return m_level; } int MapTrainerTeamMember::nature() const { return m_nature; } bool MapTrainerTeamMember::item(const int item) const { return m_item.contains(item); } MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs) { if (this == &rhs) return *this; COPY(species); COPY(level); COPY(nature); COPY(item); return *this; }