/* * 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 . */ // Pokemod includes #include "Pokemod.h" #include "Item.h" #include "ItemEffect.h" // Header include #include "SpeciesEvolution.h" const QStringList SpeciesEvolution::StyleStr = QStringList() << "Level" << "Happiness" << "Stat" << "Item" << "Trade" << "TradeItem" << "Personality" << "Spare Slot"; const QStringList SpeciesEvolution::GiveHoldStr = QStringList() <<"Give" << "Hold"; SpeciesEvolution::SpeciesEvolution(const Pokemod* pokemod, const int id) : Object("SpeciesEvolution", pokemod, id), m_species(INT_MAX), m_style(INT_MAX), m_value1(INT_MAX), m_value2(INT_MAX), m_value3(INT_MAX), m_level(0) { } SpeciesEvolution::SpeciesEvolution(const Pokemod* pokemod, const SpeciesEvolution& evolution, const int id) : Object("SpeciesEvolution", pokemod, id) { *this = evolution; } SpeciesEvolution::SpeciesEvolution(const Pokemod* pokemod, const QDomElement& xml, const int id) : Object("SpeciesEvolution", pokemod, id) { load(xml, id); } bool SpeciesEvolution::validate() const { bool valid = true; pokemod()->validationMsg(QString("------Evolution with id %1---").arg(id()), Pokemod::V_Msg); if (pokemod()->speciesIndex(m_species) == INT_MAX) { pokemod()->validationMsg("Invalid species"); valid = false; } if (m_style < S_End) { bool ok = true; switch (m_style) { case S_Happiness: case S_Stat: case S_Personality: if (Pokemod::REL_End <= m_value1) ok = false; break; case S_Item: case S_TradeItem: if (pokemod()->itemIndex(m_value1) == INT_MAX) ok = false; else { for (int i = 0; (i < pokemod()->itemById(m_value1)->effectCount()) && !ok; ++i) ok = (pokemod()->itemById(m_value1)->effect(i)->effect() == ItemEffect::E_Evolution); } break; } if (!ok) { pokemod()->validationMsg("Invalid m_value1"); valid = false; ok = true; } switch (m_style) { case S_Stat: if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value2) ok = false; case S_Item: if ((G_End <= m_value2) || ((m_value2 == G_Hold) && !pokemod()->rules()->holdItems())) ok = false; break; } if (!ok) { pokemod()->validationMsg("Invalid m_value2"); valid = false; ok = true; } } else { pokemod()->validationMsg("Invalid style"); valid = false; } if (pokemod()->rules()->maxLevel() <= m_level) { pokemod()->validationMsg("Invalid level"); valid = false; } return valid; } void SpeciesEvolution::load(const QDomElement& xml, int id) { LOAD_ID(); LOAD(int, species); LOAD(int, style); LOAD(int, value1); LOAD(int, value2); LOAD(int, value3); LOAD(int, level); } QDomElement SpeciesEvolution::save() const { SAVE_CREATE(); SAVE(int, species); SAVE(int, style); SAVE(int, value1); SAVE(int, value2); SAVE(int, value3); SAVE(int, level); return xml; } void SpeciesEvolution::setSpecies(const int species) throw(BoundsException) { if (pokemod()->speciesIndex(species) == INT_MAX) throw(BoundsException(className(), "species")); m_species = species; } void SpeciesEvolution::setStyle(const int style) throw(BoundsException) { if (S_End <= style) throw(BoundsException(className(), "style")); m_style = style; } void SpeciesEvolution::setValue1(const int value1) throw(Exception) { bool ok = false; switch (m_style) { case S_Happiness: case S_Stat: case S_Personality: if (Pokemod::REL_End <= value1) throw(BoundsException(className(), "value1")); break; case S_Item: case S_TradeItem: if (pokemod()->itemIndex(value1) == INT_MAX) throw(BoundsException(className(), "value1")); for (int i = 0; (i < pokemod()->itemById(value1)->effectCount()) && !ok; ++i) ok = (pokemod()->itemById(value1)->effect(i)->effect() == ItemEffect::E_Evolution); if (!ok) throw(BoundsException(className(), "value1")); break; default: throw(UnusedException(className(), "value1")); break; } m_value1 = value1; } void SpeciesEvolution::setValue2(const int value2) throw(Exception) { switch (m_style) { case S_Stat: if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value2) throw(BoundsException(className(), "value2")); case S_Item: if ((G_End <= value2) || ((value2 == G_Hold) && !pokemod()->rules()->holdItems())) throw(BoundsException(className(), "value2")); break; default: throw(UnusedException(className(), "value2")); break; } m_value2 = value2; } void SpeciesEvolution::setValue3(const int value3) throw(UnusedException) { switch (m_style) { case S_Happiness: case S_Stat: case S_Personality: break; default: throw(UnusedException(className(), "value3")); break; } m_value3 = value3; } void SpeciesEvolution::setLevel(const int level) throw(BoundsException) { if (pokemod()->rules()->maxLevel() < level) throw(BoundsException(className(), "level")); m_level = level; } int SpeciesEvolution::species() const { return m_species; } int SpeciesEvolution::style() const { return m_style; } int SpeciesEvolution::value1() const { return m_value1; } int SpeciesEvolution::value2() const { return m_value2; } int SpeciesEvolution::value3() const { return m_value3; } int SpeciesEvolution::level() const { return m_level; } SpeciesEvolution& SpeciesEvolution::operator=(const SpeciesEvolution& rhs) { if (this == &rhs) return *this; COPY(species); COPY(style); COPY(value1); COPY(value2); COPY(level); return *this; }