diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2008-09-05 20:41:05 +0000 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2008-09-05 20:41:05 +0000 |
commit | b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7 (patch) | |
tree | 6609f31b1635d948cf7a216c7fea72cfb3c905a0 /sigmod | |
parent | b99ffef4aa68dd5f0af64de9aec0f610e267d8cc (diff) | |
download | sigen-b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7.tar.gz sigen-b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7.tar.xz sigen-b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7.zip |
[FIX] Moving stuff for the move to the new name, Sigma Game Engine (sigen for short)
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@249 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'sigmod')
79 files changed, 12989 insertions, 0 deletions
diff --git a/sigmod/Ability.cpp b/sigmod/Ability.cpp new file mode 100644 index 00000000..02dc7280 --- /dev/null +++ b/sigmod/Ability.cpp @@ -0,0 +1,143 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Ability.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +Pokemod::Ability::Ability(const Ability& ability) : + Object(ability.parent(), ability.id()) +{ + *this = ability; +} + +Pokemod::Ability::Ability(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_priority(0), + m_description(""), + m_battleScript("", ""), + m_worldScript("", "") +{ +} + +Pokemod::Ability::Ability(const Ability& ability, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = ability; +} + +Pokemod::Ability::Ability(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Ability::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::Ability::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(priority); + LOAD(description); + LOAD(battleScript); + LOAD(worldScript); +} + +QDomElement Pokemod::Ability::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(priority); + SAVE(description); + SAVE(battleScript); + SAVE(worldScript); + return xml; +} + +void Pokemod::Ability::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Ability::setPriority(const int priority) +{ + CHECK(priority); +} + +void Pokemod::Ability::setDescription(const QString& description) +{ + CHECK(description); +} + +void Pokemod::Ability::setBattleScript(const Script& battleScript) +{ + CHECK(battleScript); +} + +void Pokemod::Ability::setWorldScript(const Script& worldScript) +{ + CHECK(worldScript); +} + +QString Pokemod::Ability::name() const +{ + return m_name; +} + +int Pokemod::Ability::priority() const +{ + return m_priority; +} + +QString Pokemod::Ability::description() const +{ + return m_description; +} + +Pokemod::Script Pokemod::Ability::battleScript() const +{ + return m_battleScript; +} + +Pokemod::Script Pokemod::Ability::worldScript() const +{ + return m_worldScript; +} + +Pokemod::Ability& Pokemod::Ability::operator=(const Ability& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(priority); + COPY(description); + COPY(battleScript); + COPY(worldScript); + return *this; +} diff --git a/sigmod/Ability.h b/sigmod/Ability.h new file mode 100644 index 00000000..b654d990 --- /dev/null +++ b/sigmod/Ability.h @@ -0,0 +1,67 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_ABILITY__ +#define __POKEMOD_ABILITY__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Ability : public Object +{ + Q_OBJECT + + public: + Ability(const Ability& ability); + Ability(const Pokemod* parent, const int id); + Ability(const Ability& ability, const Pokemod* parent, const int id); + Ability(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setPriority(const int priority); + void setDescription(const QString& description); + void setBattleScript(const Script& battleScript); + void setWorldScript(const Script& worldScript); + + QString name() const; + int priority() const; + QString description() const; + Script battleScript() const; + Script worldScript() const; + + Ability& operator=(const Ability& rhs); + private: + QString m_name; + int m_priority; + QString m_description; + Script m_battleScript; + Script m_worldScript; +}; +} + +#endif diff --git a/sigmod/Author.cpp b/sigmod/Author.cpp new file mode 100644 index 00000000..f5def288 --- /dev/null +++ b/sigmod/Author.cpp @@ -0,0 +1,124 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Author.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +// Qt includes +#include <QtCore/QRegExp> + +Pokemod::Author::Author(const Author& author) : + Object(author.parent(), author.id()) +{ + *this = author; +} + +Pokemod::Author::Author(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_email(""), + m_role("") +{ +} + +Pokemod::Author::Author(const Author& author, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = author; +} + +Pokemod::Author::Author(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Author::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + if (m_email.isEmpty()) + emit(warning("Email is empty")); + else if (!QRegExp("[a-zA-Z0-9%-_\\.]+@[a-zA-Z0-9\\-]+(\\.[a-zA-Z]+)*\\.[a-zA-Z]{2,4}").exactMatch(m_email)) + emit(error("Email is invalid")); + if (m_role.isEmpty()) + emit(error("Role is empty")); + TEST_END(); +} + +void Pokemod::Author::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(email); + LOAD(role); +} + +QDomElement Pokemod::Author::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(email); + SAVE(role); + return xml; +} + +void Pokemod::Author::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Author::setEmail(const QString& email) +{ + CHECK(email); +} + +void Pokemod::Author::setRole(const QString& role) +{ + CHECK(role); +} + +QString Pokemod::Author::name() const +{ + return m_name; +} + +QString Pokemod::Author::email() const +{ + return m_email; +} + +QString Pokemod::Author::role() const +{ + return m_role; +} + +Pokemod::Author& Pokemod::Author::operator=(const Author& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(email); + COPY(role); + return *this; +} diff --git a/sigmod/Author.h b/sigmod/Author.h new file mode 100644 index 00000000..23f36b38 --- /dev/null +++ b/sigmod/Author.h @@ -0,0 +1,60 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_AUTHOR__ +#define __POKEMOD_AUTHOR__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Author : public Object +{ + Q_OBJECT + + public: + Author(const Author& author); + Author(const Pokemod* parent, const int id); + Author(const Author& author, const Pokemod* parent, const int id); + Author(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setEmail(const QString& email); + void setRole(const QString& role); + + QString name() const; + QString email() const; + QString role() const; + + Author& operator=(const Author& rhs); + private: + QString m_name; + QString m_email; + QString m_role; +}; +} + +#endif diff --git a/sigmod/Badge.cpp b/sigmod/Badge.cpp new file mode 100644 index 00000000..821720af --- /dev/null +++ b/sigmod/Badge.cpp @@ -0,0 +1,195 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Badge.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Rules.h" +#include "Sprite.h" + +Pokemod::Badge::Badge(const Badge& badge) : + Object(badge.parent(), badge.id()), + m_stat(ST_End_GSC - ST_No_HP_Start) +{ + *this = badge; +} + +Pokemod::Badge::Badge(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_face(-1), + m_badge(-1), + m_obey(0), + m_stat(ST_End_GSC - ST_No_HP_Start) +{ + for (int i = 0; i < m_stat.size(); ++i) + m_stat[i].set(1, 1); +} + +Pokemod::Badge::Badge(const Badge& badge, const Pokemod* parent, const int id) : + Object(parent, id), + m_stat(ST_End_GSC - ST_No_HP_Start) +{ + *this = badge; +} + +Pokemod::Badge::Badge(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id), + m_stat(ST_End_GSC - ST_No_HP_Start) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Badge::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setFace, face); + TEST(setBadge, badge); + TEST(setObey, obey); + TEST_ARRAY(setStat, stat, ST_End_GSC); + TEST_END(); +} + +void Pokemod::Badge::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(face); + LOAD(badge); + LOAD(obey); + LOAD_ARRAY(stat); +} + +QDomElement Pokemod::Badge::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(face); + SAVE(badge); + SAVE(obey); + SAVE_ARRAY(stat); + return xml; +} + +void Pokemod::Badge::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Badge::setFace(const int face) +{ + if (qobject_cast<const Pokemod*>(pokemod())->spriteIndex(face) == INT_MAX) + emit(error(bounds("face"))); + else + CHECK(face); +} + +void Pokemod::Badge::setBadge(const int badge) +{ + if (qobject_cast<const Pokemod*>(pokemod())->spriteIndex(badge) == INT_MAX) + emit(error(bounds("badge"))); + else + CHECK(badge); +} + +void Pokemod::Badge::setObey(const int obey) +{ + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < obey) + { + emit(error(bounds("obey"))); + return; + } + CHECK(obey); +} + +void Pokemod::Badge::setStat(const Stat stat, const Fraction& multiplier) +{ + if (multiplier < 1) + { + emit(error(bounds("stat multiplier"))); + return; + } + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_Attack ... ST_Special: + break; + default: + emit(warning(bounds("stat"))); + return; + } + CHECK_ARRAY(stat[stat - ST_No_HP_Start], multiplier); +} + +void Pokemod::Badge::setStat(const Fraction& multiplier) +{ + if (multiplier < 1) + emit(error(bounds("stat multiplier"))); +} + +QString Pokemod::Badge::name() const +{ + return m_name; +} + +int Pokemod::Badge::face() const +{ + return m_face; +} + +int Pokemod::Badge::badge() const +{ + return m_badge; +} + +int Pokemod::Badge::obey() const +{ + return m_obey; +} + +Pokemod::Fraction Pokemod::Badge::stat(const Stat stat) const +{ + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_Attack ... ST_Special: + return m_stat[stat - ST_No_HP_Start]; + default: + emit(warning(bounds("stat"))); + return Fraction(); + } +} + +Pokemod::Badge& Pokemod::Badge::operator=(const Badge& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(face); + COPY(badge); + COPY(obey); + COPY(stat); + return *this; +} diff --git a/sigmod/Badge.h b/sigmod/Badge.h new file mode 100644 index 00000000..1ff97f90 --- /dev/null +++ b/sigmod/Badge.h @@ -0,0 +1,69 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_BADGE__ +#define __POKEMOD_BADGE__ + +// Pokemod includes +#include "Fraction.h" +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Badge : public Object +{ + Q_OBJECT + + public: + Badge(const Badge& badge); + Badge(const Pokemod* parent, const int id); + Badge(const Badge& badge, const Pokemod* parent, const int id); + Badge(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setFace(const int face); + void setBadge(const int badge); + void setObey(const int obey); + void setStat(const Stat stat, const Fraction& multiplier); + + QString name() const; + int face() const; + int badge() const; + int obey() const; + Fraction stat(const Stat stat) const; + + Badge& operator=(const Badge& rhs); + private: + void setStat(const Fraction& multiplier); + + QString m_name; + int m_face; + int m_badge; + int m_obey; + QVarLengthArray<Fraction, ST_End_GSC - ST_No_HP_Start> m_stat; +}; +} + +#endif diff --git a/sigmod/CMakeLists.txt b/sigmod/CMakeLists.txt new file mode 100644 index 00000000..06b16f29 --- /dev/null +++ b/sigmod/CMakeLists.txt @@ -0,0 +1,124 @@ +PROJECT(pokemod) + +IF(NOT BUILT_FROM_ROOT) + MESSAGE(FATAL_ERROR "Not built from source root") +ENDIF(NOT BUILT_FROM_ROOT) + +ADD_DEFINITIONS(-DMAKE_POKEMOD_LIB) + +SET(pokemod_MOC_HEADERS + Ability.h + Author.h + Badge.h + CoinList.h + CoinListObject.h + EggGroup.h + GlobalScript.h + Item.h + ItemType.h + MapEffect.h + Map.h + MapTrainer.h + MapTrainerTeamMember.h + MapWarp.h + MapWildListEncounter.h + MapWildList.h + Move.h + Nature.h + Object.h + Pokemod.h + Rules.h + Skin.h + Sound.h + Species.h + SpeciesAbility.h + SpeciesItem.h + SpeciesMove.h + Sprite.h + Status.h + Store.h + Tile.h + Time.h + Trainer.h + Type.h + Weather.h +) +QT4_WRAP_CPP(pokemod_MOC_SRCS ${pokemod_MOC_HEADERS}) +SET(pokemod_HEADERS + Fraction.h + Global.h + Hat.h + Macros.h + Matrix.h + Script.h +) +SET(pokemod_DEVEL + ${pokemod_HEADERS} + ${pokemod_MOC_HEADERS} +) +SET(pokemod_SRCS + Ability.cpp + Author.cpp + Badge.cpp + CoinList.cpp + CoinListObject.cpp + EggGroup.cpp + Fraction.cpp + GlobalScript.cpp + Item.cpp + ItemType.cpp + Map.cpp + MapEffect.cpp + MapTrainer.cpp + MapTrainerTeamMember.cpp + MapWarp.cpp + MapWildList.cpp + MapWildListEncounter.cpp + Move.cpp + Nature.cpp + Object.cpp + Pokemod.cpp + Rules.cpp + Skin.cpp + Sound.cpp + Species.cpp + SpeciesAbility.cpp + SpeciesItem.cpp + SpeciesMove.cpp + Sprite.cpp + Status.cpp + Store.cpp + Tile.cpp + Time.cpp + Trainer.cpp + Type.cpp + Weather.cpp +) + +ADD_LIBRARY(pokemod + ${pokemod_SRCS} + ${pokemod_MOC_SRCS} +) +SET_TARGET_PROPERTIES(pokemod + PROPERTIES + VERSION ${POKEGEN_VERSION} + SOVERSION ${POKEGEN_SOVERSION} + LINK_INTERFACE_LIBRARIES "" +) +TARGET_LINK_LIBRARIES(pokemod + ${QT_QTCORE_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${QT_QTXML_LIBRARY} +) + +INSTALL( + TARGETS pokemod + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX} + COMPONENT runtime +) + +INSTALL( + FILES ${pokemod_DEVEL} + DESTINATION ${CMAKE_INSTALL_PREFIX}/include/${CMAKE_PROJECT_NAME}/${PROJECT_NAME} + COMPONENT development +) diff --git a/sigmod/CoinList.cpp b/sigmod/CoinList.cpp new file mode 100644 index 00000000..c19d325a --- /dev/null +++ b/sigmod/CoinList.cpp @@ -0,0 +1,233 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "CoinList.h" + +// Pokemod includes +#include "CoinListObject.h" +#include "Macros.h" +#include "Pokemod.h" + +// Qt includes +#include <QtCore/QSet> + +Pokemod::CoinList::CoinList(const CoinList& coinList) : + Object(coinList.parent(), coinList.id()) +{ + *this = coinList; +} + +Pokemod::CoinList::CoinList(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_script("", "") +{ +} + +Pokemod::CoinList::CoinList(const CoinList& coinList, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = coinList; +} + +Pokemod::CoinList::CoinList(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::CoinList::~CoinList() +{ + clear(); +} + +void Pokemod::CoinList::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + if (!objectCount()) + emit(error("There are no objects")); + QSet<int> idChecker; + QSet<int> itemChecker; + QSet<int> speciesChecker; + TEST_SUB_BEGIN(CoinListObject, objects); + TEST_SUB("object", id); + if (object->type() == CoinListObject::Item) + { + TEST_SUB_RAW(item, "object item", object); + } + else if (object->type() == CoinListObject::Species) + { + TEST_SUB_RAW(species, "object species", object); + } + TEST_SUB_END(); +// foreach (CoinListObject* object, m_objects) +// { +// object->validate(); +// if (idChecker.contains(object->id())) +// emit(error(subclass("object", object->id()))); +// idChecker.insert(object->id()); +// if (object->type() == CoinListObject::Item) +// { +// if (itemChecker.contains(object->object())) +// emit(error(subclass("object item", object->id()))); +// itemChecker.insert(object->object()); +// } +// else if (object->type() == CoinListObject::Species) +// { +// if (speciesChecker.contains(object->object())) +// emit(error(subclass("object species", object->id()))); +// speciesChecker.insert(object->object()); +// } +// } + TEST_END(); +} + +void Pokemod::CoinList::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(script); + LOAD_SUB(newObject, CoinListObject); +} + +QDomElement Pokemod::CoinList::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(script); + SAVE_SUB(CoinListObject, objects); + return xml; +} + +void Pokemod::CoinList::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::CoinList::setScript(const Script& script) +{ + CHECK(script) +} + +QString Pokemod::CoinList::name() const +{ + return m_name; +} + +Pokemod::Script Pokemod::CoinList::script() const +{ + return m_script; +} + +const Pokemod::CoinListObject* Pokemod::CoinList::object(const int index) const +{ + Q_ASSERT(index < objectCount()); + return m_objects.at(index); +} + +Pokemod::CoinListObject* Pokemod::CoinList::object(const int index) +{ + Q_ASSERT(index < objectCount()); + return m_objects[index]; +} + +const Pokemod::CoinListObject* Pokemod::CoinList::objectById(const int id) const +{ + return object(objectIndex(id)); +} + +Pokemod::CoinListObject* Pokemod::CoinList::objectById(const int id) +{ + return object(objectIndex(id)); +} + +int Pokemod::CoinList::objectIndex(const int id) const +{ + for (int i = 0; i < objectCount(); ++i) + { + if (m_objects[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::CoinList::objectCount() const +{ + return m_objects.size(); +} + +Pokemod::CoinListObject* Pokemod::CoinList::newObject() +{ + return newObject(new CoinListObject(this, objectId())); +} + +Pokemod::CoinListObject* Pokemod::CoinList::newObject(const QDomElement& xml) +{ + return newObject(new CoinListObject(xml, this, objectId())); +} + +Pokemod::CoinListObject* Pokemod::CoinList::newObject(const CoinListObject& object) +{ + return newObject(new CoinListObject(object, this, objectId())); +} + +Pokemod::CoinListObject* Pokemod::CoinList::newObject(CoinListObject* object) +{ + m_objects.append(object); + return object; +} + +void Pokemod::CoinList::deleteObject(const int index) +{ + Q_ASSERT(index < objectCount()); + delete m_objects[index]; + m_objects.removeAt(index); +} + +void Pokemod::CoinList::deleteObjectById(const int id) +{ + deleteObject(objectIndex(id)); +} + +int Pokemod::CoinList::objectId() const +{ + int i = 0; + while ((i < objectCount()) && (objectIndex(i) != INT_MAX)) + ++i; + return i; +} + +Pokemod::CoinList& Pokemod::CoinList::operator=(const CoinList& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(name); + COPY(script); + COPY_SUB(CoinListObject, objects); + return *this; +} + +void Pokemod::CoinList::clear() +{ + while (objectCount()) + deleteObject(0); +} diff --git a/sigmod/CoinList.h b/sigmod/CoinList.h new file mode 100644 index 00000000..a04503cc --- /dev/null +++ b/sigmod/CoinList.h @@ -0,0 +1,81 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_COINLIST__ +#define __POKEMOD_COINLIST__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +// Qt includes +#include <QtCore/QList> + +namespace Pokemod +{ +// Forward declarations +class CoinListObject; +class Pokemod; + +class POKEMOD_EXPORT CoinList : public Object +{ + Q_OBJECT + + public: + CoinList(const CoinList& coinList); + CoinList(const Pokemod* parent, const int id); + CoinList(const CoinList& coinList, const Pokemod* parent, const int id); + CoinList(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~CoinList(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setScript(const Script& script); + + QString name() const; + Script script() const; + + const CoinListObject* object(const int index) const; + CoinListObject* object(const int index); + const CoinListObject* objectById(const int id) const; + CoinListObject* objectById(const int id); + int objectIndex(const int id) const; + int objectCount() const; + CoinListObject* newObject(); + CoinListObject* newObject(const QDomElement& xml); + CoinListObject* newObject(const CoinListObject& object); + void deleteObject(const int index); + void deleteObjectById(const int id); + + CoinList& operator=(const CoinList& rhs); + private: + int objectId() const; + CoinListObject* newObject(CoinListObject* object); + + void clear(); + + QString m_name; + Script m_script; + QList<CoinListObject*> m_objects; +}; +} + +#endif diff --git a/sigmod/CoinListObject.cpp b/sigmod/CoinListObject.cpp new file mode 100644 index 00000000..8ff85afb --- /dev/null +++ b/sigmod/CoinListObject.cpp @@ -0,0 +1,138 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "CoinListObject.h" + +// Pokemod includes +#include "CoinList.h" +#include "Macros.h" +#include "Pokemod.h" + +const QStringList Pokemod::CoinListObject::TypeStr = QStringList() << "Item" << "Team Member"; + +Pokemod::CoinListObject::CoinListObject(const CoinListObject& object) : + Object(object.parent(), object.id()) +{ + *this = object; +} + +Pokemod::CoinListObject::CoinListObject(const CoinList* parent, const int id) : + Object(parent, id), + m_type(Item), + m_object(INT_MAX), + m_amount(1), + m_cost(0) +{ +} + +Pokemod::CoinListObject::CoinListObject(const CoinListObject& object, const CoinList* parent, const int id) : + Object(parent, id) +{ + *this = object; +} + +Pokemod::CoinListObject::CoinListObject(const QDomElement& xml, const CoinList* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::CoinListObject::validate() +{ + TEST_BEGIN(); + TEST(setObject, object); + TEST(setAmount, amount); + TEST_END(); +} + +void Pokemod::CoinListObject::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(type); + LOAD(object); + LOAD(amount); + LOAD(cost); +} + +QDomElement Pokemod::CoinListObject::save() const +{ + SAVE_CREATE(); + SAVE(type); + SAVE(object); + SAVE(amount); + SAVE(cost); + return xml; +} + +void Pokemod::CoinListObject::setType(const Type type) +{ + CHECK(type); +} + +void Pokemod::CoinListObject::setObject(const int object) +{ + if (((Item == m_type) && (qobject_cast<const Pokemod*>(pokemod())->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (qobject_cast<const Pokemod*>(pokemod())->speciesIndex(object) == INT_MAX))) + emit(error(bounds("object"))); + else + CHECK(object); +} + +void Pokemod::CoinListObject::setAmount(const int amount) +{ + if (!amount || ((Species == m_type) && (1 < amount))) + emit(error(bounds("amount"))); + else + CHECK(amount); +} + +void Pokemod::CoinListObject::setCost(const int cost) +{ + CHECK(cost); +} + +Pokemod::CoinListObject::Type Pokemod::CoinListObject::type() const +{ + return m_type; +} + +int Pokemod::CoinListObject::object() const +{ + return m_object; +} + +int Pokemod::CoinListObject::amount() const +{ + return m_amount; +} + +int Pokemod::CoinListObject::cost() const +{ + return m_cost; +} + +Pokemod::CoinListObject& Pokemod::CoinListObject::operator=(const CoinListObject& rhs) +{ + if (this == &rhs) + return *this; + COPY(type); + COPY(object); + COPY(amount); + COPY(cost); + return *this; +} diff --git a/sigmod/CoinListObject.h b/sigmod/CoinListObject.h new file mode 100644 index 00000000..a1d9ab6b --- /dev/null +++ b/sigmod/CoinListObject.h @@ -0,0 +1,72 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_COINLISTOBJECT__ +#define __POKEMOD_COINLISTOBJECT__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class CoinList; + +class POKEMOD_EXPORT CoinListObject : public Object +{ + Q_OBJECT + Q_ENUMS(Type) + + public: + enum Type + { + Item = 0, + Species = 1 + }; + static const QStringList TypeStr; + + CoinListObject(const CoinListObject& object); + CoinListObject(const CoinList* parent, const int id); + CoinListObject(const CoinListObject& object, const CoinList* parent, const int id); + CoinListObject(const QDomElement& xml, const CoinList* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setType(const Type type); + void setObject(const int object); + void setAmount(const int amount); + void setCost(const int cost); + + Type type() const; + int object() const; + int amount() const; + int cost() const; + + CoinListObject& operator=(const CoinListObject& rhs); + private: + Type m_type; + int m_object; + int m_amount; + int m_cost; +}; +} +Q_DECLARE_METATYPE(Pokemod::CoinListObject::Type) + +#endif diff --git a/sigmod/EggGroup.cpp b/sigmod/EggGroup.cpp new file mode 100644 index 00000000..4f028611 --- /dev/null +++ b/sigmod/EggGroup.cpp @@ -0,0 +1,87 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "EggGroup.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +Pokemod::EggGroup::EggGroup(const EggGroup& eggGroup) : + Object(eggGroup.parent(), eggGroup.id()) +{ + *this = eggGroup; +} + +Pokemod::EggGroup::EggGroup(const Pokemod* parent, const int id) : + Object(parent, id), + m_name("") +{ +} + +Pokemod::EggGroup::EggGroup(const EggGroup& eggGroup, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = eggGroup; +} + +Pokemod::EggGroup::EggGroup(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::EggGroup::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::EggGroup::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); +} + +QDomElement Pokemod::EggGroup::save() const +{ + SAVE_CREATE(); + SAVE(name); + return xml; +} + +void Pokemod::EggGroup::setName(const QString& name) +{ + CHECK(name); +} + +QString Pokemod::EggGroup::name() const +{ + return m_name; +} + +Pokemod::EggGroup& Pokemod::EggGroup::operator=(const EggGroup& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + return *this; +} diff --git a/sigmod/EggGroup.h b/sigmod/EggGroup.h new file mode 100644 index 00000000..5d2927f7 --- /dev/null +++ b/sigmod/EggGroup.h @@ -0,0 +1,54 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_EGGGROUP__ +#define __POKEMOD_EGGGROUP__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT EggGroup : public Object +{ + Q_OBJECT + + public: + EggGroup(const EggGroup& eggGroup); + EggGroup(const Pokemod* parent, const int id); + EggGroup(const EggGroup& eggGroup, const Pokemod* parent, const int id); + EggGroup(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + + QString name() const; + + EggGroup& operator=(const EggGroup& rhs); + private: + QString m_name; +}; +} + +#endif diff --git a/sigmod/Fraction.cpp b/sigmod/Fraction.cpp new file mode 100644 index 00000000..33c9add0 --- /dev/null +++ b/sigmod/Fraction.cpp @@ -0,0 +1,150 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Fraction.h" + +Pokemod::Fraction::Fraction(const int numerator, const int denominator) +{ + set(numerator, denominator); + reduce(); +} + +Pokemod::Fraction::Fraction(const Fraction& fraction) +{ + set(fraction.numerator(), fraction.denominator()); + reduce(); +} + +void Pokemod::Fraction::set(const int numerator, const int denominator) +{ + m_numerator = numerator; + m_denominator = denominator; + normalize(); +} + +void Pokemod::Fraction::setNumerator(const int numerator) +{ + set(numerator, m_denominator); +} + +void Pokemod::Fraction::setDenominator(const int denominator) +{ + set(m_numerator, denominator); +} + +int Pokemod::Fraction::numerator() const +{ + return m_numerator; +} + +int Pokemod::Fraction::denominator() const +{ + return m_denominator; +} + +void Pokemod::Fraction::reduce() +{ + if (!m_numerator || !m_denominator) + return; + int i = m_numerator; + int j = m_denominator; + if (i < 0) + i = -i; + while (i - j) + (i > j) ? (i -= j) : (j -= i); + m_numerator /= i; + m_denominator /= i; +} + +bool Pokemod::Fraction::poll() const +{ + return (qrand() % m_denominator) < m_numerator; +} + +Pokemod::Fraction& Pokemod::Fraction::operator=(const Fraction& rhs) +{ + if (this == &rhs) + return *this; + m_numerator = rhs.m_numerator; + m_denominator = rhs.m_denominator; + return *this; +} + +Pokemod::Fraction::operator double() const +{ + return (double(m_numerator) / m_denominator); +} + +Pokemod::Fraction Pokemod::Fraction::operator+(const Fraction& rhs) const +{ + return Fraction((m_numerator * rhs.m_denominator) + (m_denominator * rhs.m_numerator), m_denominator * rhs.m_denominator); +} + +Pokemod::Fraction Pokemod::Fraction::operator-(const Fraction& rhs) const +{ + return Fraction((m_numerator * rhs.m_denominator) - (m_denominator * rhs.m_numerator), m_denominator * rhs.m_denominator); +} + +Pokemod::Fraction Pokemod::Fraction::operator*(const Fraction& rhs) const +{ + return Fraction(m_numerator * rhs.m_numerator, m_denominator * rhs.m_denominator); +} + +Pokemod::Fraction Pokemod::Fraction::operator/(const Fraction& rhs) const +{ + return Fraction(m_numerator * rhs.m_denominator, m_denominator * rhs.m_numerator); +} + +Pokemod::Fraction& Pokemod::Fraction::operator+=(const Fraction& rhs) +{ + return *this = *this + rhs; +} + +Pokemod::Fraction& Pokemod::Fraction::operator-=(const Fraction& rhs) +{ + return *this = *this - rhs; +} + +Pokemod::Fraction& Pokemod::Fraction::operator*=(const Fraction& rhs) +{ + return *this = *this * rhs; +} + +Pokemod::Fraction& Pokemod::Fraction::operator/=(const Fraction& rhs) +{ + return *this = *this / rhs; +} + +bool Pokemod::Fraction::operator==(const Fraction& rhs) const +{ + return ((m_numerator == rhs.m_numerator) && (m_denominator == rhs.m_denominator)); +} + +bool Pokemod::Fraction::operator!=(const Fraction& rhs) const +{ + return !(*this == rhs); +} + +void Pokemod::Fraction::normalize() +{ + if (m_denominator < 0) + { + m_denominator = -m_denominator; + m_numerator = -m_numerator; + } +} diff --git a/sigmod/Fraction.h b/sigmod/Fraction.h new file mode 100644 index 00000000..82f42c2e --- /dev/null +++ b/sigmod/Fraction.h @@ -0,0 +1,68 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_FRACTION__ +#define __POKEMOD_FRACTION__ + +// Pokemod includes +#include "Global.h" + +// Qt includes +#include <QtCore/QMetaType> + +namespace Pokemod +{ +class POKEMOD_EXPORT Fraction +{ + public: + explicit Fraction(const int numerator = 1, const int denominator = 1); + Fraction(const Fraction& fraction); + + void set(const int numerator, const int denominator); + void setNumerator(const int numerator); + void setDenominator(const int denominator); + + int numerator() const; + int denominator() const; + + void reduce(); + bool poll() const; + + Fraction& operator=(const Fraction& rhs); + operator double() const; + Fraction operator+(const Fraction& rhs) const; + Fraction operator-(const Fraction& rhs) const; + Fraction operator*(const Fraction& rhs) const; + Fraction operator/(const Fraction& rhs) const; + Fraction operator%(const Fraction& rhs) const; + Fraction& operator+=(const Fraction& rhs); + Fraction& operator-=(const Fraction& rhs); + Fraction& operator*=(const Fraction& rhs); + Fraction& operator/=(const Fraction& rhs); + Fraction& operator%=(const Fraction& rhs); + bool operator==(const Fraction& rhs) const; + bool operator!=(const Fraction& rhs) const; + protected: + void normalize(); + private: + int m_numerator; + int m_denominator; +}; +} +Q_DECLARE_METATYPE(Pokemod::Fraction) + +#endif diff --git a/sigmod/Global.h b/sigmod/Global.h new file mode 100644 index 00000000..4e81f860 --- /dev/null +++ b/sigmod/Global.h @@ -0,0 +1,78 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_GLOBAL__ +#define __POKEMOD_GLOBAL__ + +// Qt includes +#include <QtCore/QMetaType> +#include <QtCore/QStringList> + +// KDE includes +#include <kdemacros.h> + +#ifndef POKEMOD_EXPORT +# ifdef MAKE_POKEMOD_LIB + /* We are building this library */ +# define POKEMOD_EXPORT KDE_EXPORT +# else + /* We are using this library */ +# define POKEMOD_EXPORT KDE_IMPORT +# endif +#endif + +# ifndef POKEMOD_EXPORT_DEPRECATED +# define POKEMOD_EXPORT_DEPRECATED KDE_DEPRECATED POKEMOD_EXPORT +# endif + +namespace Pokemod +{ +enum Stat +{ + ST_HP = 0, + ST_No_HP_Start = 1, + ST_Attack = 1, + ST_Defense = 2, + ST_Speed = 3, + ST_Special = 4, + ST_End_RBY = 5, + ST_SpecialAttack = 4, + ST_SpecialDefense = 5, + ST_End_GSC = 6, + ST_Accuracy = 6, + ST_Evasion = 7, + ST_End_Battle = 8 +}; +const QStringList StatRBYStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special" << "Special" << "Accuracy" << "Evasion"; +const QStringList StatGSCStr = QStringList() << "HP" << "Attack" << "Defense" << "Speed" << "Special Attack" << "Special Defense" << "Accuracy" << "Evasion"; + +enum Direction +{ + D_Up = 0, + D_Down = 1, + D_Left = 2, + D_Right = 3, + D_End = 4, + D_None = 4 +}; +const QStringList DirectionStr = QStringList() << "Up" << "Down" << "Left" << "Right" << "None"; + +} +Q_DECLARE_METATYPE(Pokemod::Stat) +Q_DECLARE_METATYPE(Pokemod::Direction) + +#endif diff --git a/sigmod/GlobalScript.cpp b/sigmod/GlobalScript.cpp new file mode 100644 index 00000000..7014c07d --- /dev/null +++ b/sigmod/GlobalScript.cpp @@ -0,0 +1,105 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "GlobalScript.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +Pokemod::GlobalScript::GlobalScript(const GlobalScript& globalScript) : + Object(globalScript.parent(), globalScript.id()) +{ + *this = globalScript; +} + +Pokemod::GlobalScript::GlobalScript(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_script("", "") +{ +} + +Pokemod::GlobalScript::GlobalScript(const GlobalScript& globalScript, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = globalScript; +} + +Pokemod::GlobalScript::GlobalScript(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::GlobalScript::~GlobalScript() +{ +} + +void Pokemod::GlobalScript::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::GlobalScript::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(script); +} + +QDomElement Pokemod::GlobalScript::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(script); + return xml; +} + +void Pokemod::GlobalScript::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::GlobalScript::setScript(const Script& script) +{ + CHECK(script); +} + +QString Pokemod::GlobalScript::name() const +{ + return m_name; +} + +Pokemod::Script Pokemod::GlobalScript::script() const +{ + return m_script; +} + +Pokemod::GlobalScript& Pokemod::GlobalScript::operator=(const GlobalScript& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(script); + return *this; +} diff --git a/sigmod/GlobalScript.h b/sigmod/GlobalScript.h new file mode 100644 index 00000000..097cd8a5 --- /dev/null +++ b/sigmod/GlobalScript.h @@ -0,0 +1,59 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_GLOBALSCRIPT__ +#define __POKEMOD_GLOBALSCRIPT__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT GlobalScript : public Object +{ + Q_OBJECT + + public: + GlobalScript(const GlobalScript& globalScript); + GlobalScript(const Pokemod* parent, const int id); + GlobalScript(const GlobalScript& globalScript, const Pokemod* parent, const int id); + GlobalScript(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~GlobalScript(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setScript(const Script& script); + + QString name() const; + Script script() const; + + GlobalScript& operator=(const GlobalScript& rhs); + private: + QString m_name; + Script m_script; +}; +} + +#endif diff --git a/sigmod/Hat.h b/sigmod/Hat.h new file mode 100644 index 00000000..9fa1a71b --- /dev/null +++ b/sigmod/Hat.h @@ -0,0 +1,134 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_HAT__ +#define __POKEMOD_HAT__ + +// Pokemod includes +#include "Global.h" + +// Qt includes +#include <QtCore/QtGlobal> +#include <QtCore/QMap> + +namespace Pokemod +{ +template<class T> class Hat +{ + public: + Hat(); + + T pick() const; + T take(); + T takeAndClear(); + void setCount(const T& key, const int weight); + void add(const T& key, const int weight); + int distinctCount() const; + int count() const; + int count(const T& key) const; + double chance(const T& key) const; + + int operator[](const T& key) const; + private: + QMap<T, int> m_objects; + int m_count; +}; + +template<class T> inline Hat<T>::Hat() : + m_count(0) +{ +} + +template<class T> inline T Hat<T>::pick() const +{ + int choice = qrand() % m_count; + foreach (T key, m_objects.keys()) + { + choice -= m_objects[key]; + if (choice < 0) + return key; + } + return T(); +} + +template<class T> inline T Hat<T>::take() +{ + T chosen = pick(); + if (!(--m_objects[chosen])) + m_objects.remove(chosen); + --m_count; + return chosen; +} + +template<class T> inline T Hat<T>::takeAndClear() +{ + T chosen = pick(); + m_count -= m_objects[chosen]; + m_objects.remove(chosen); + return chosen; +} + +template<class T> inline void Hat<T>::setCount(const T& key, const int weight) +{ + if (m_objects.contains(key)) + m_count -= m_objects[key]; + if (weight) + { + m_objects[key] = weight; + m_count += weight; + } + else + m_objects.remove(key); +} + +template<class T> inline void Hat<T>::add(const T& key, const int weight) +{ + Q_ASSERT(0 < weight); + m_objects[key] += weight; + m_count += weight; +} + +template<class T> inline int Hat<T>::distinctCount() const +{ + return m_objects.size(); +} + +template<class T> inline int Hat<T>::count() const +{ + return m_count; +} + +template<class T> inline int Hat<T>::count(const T& key) const +{ + if (m_objects.contains(key)) + return m_objects[key]; + return 0; +} + +template<class T> inline double Hat<T>::chance(const T& key) const +{ + return (double(count(key)) / m_count); +} + +template<class T> inline int Hat<T>::operator[](const T& key) const +{ + return count(key); +} + +} + +#endif diff --git a/sigmod/Item.cpp b/sigmod/Item.cpp new file mode 100644 index 00000000..a2a64b0f --- /dev/null +++ b/sigmod/Item.cpp @@ -0,0 +1,173 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Item.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Rules.h" + +// Qt includes +#include <QtCore/QSet> + +Pokemod::Item::Item(const Item& item) : + Object(item.parent(), item.id()) +{ + *this = item; +} + +Pokemod::Item::Item(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_sellable(false), + m_type(INT_MAX), + m_price(0), + m_description(""), + m_script("", "") +{ +} + +Pokemod::Item::Item(const Item& item, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = item; +} + +Pokemod::Item::Item(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::Item::~Item() +{ +} + +void Pokemod::Item::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setType, type); + TEST(setPrice, price); + TEST_END(); +} + +void Pokemod::Item::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(sellable); + LOAD(type); + LOAD(price); + LOAD(description); + LOAD(script); +} + +QDomElement Pokemod::Item::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(sellable); + SAVE(type); + SAVE(price); + SAVE(description); + SAVE(script); + return xml; +} + +void Pokemod::Item::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Item::setSellable(const bool sellable) +{ + CHECK(sellable); +} + +void Pokemod::Item::setType(const int type) +{ + if (qobject_cast<const Pokemod*>(pokemod())->itemTypeIndex(type) == INT_MAX) + emit(error(bounds("type"))); + else + CHECK(type); +} + +void Pokemod::Item::setPrice(const int price) +{ + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxMoney() < price) + emit(error(bounds("price"))); + else + CHECK(price); +} + +void Pokemod::Item::setDescription(const QString& description) +{ + CHECK(description); +} + +void Pokemod::Item::setScript(const Script& script) +{ + CHECK(script); +} + +QString Pokemod::Item::name() const +{ + return m_name; +} + +bool Pokemod::Item::sellable() const +{ + return m_sellable; +} + +int Pokemod::Item::type() const +{ + return m_type; +} + +int Pokemod::Item::price() const +{ + return m_price; +} + +QString Pokemod::Item::description() const +{ + return m_description; +} + +Pokemod::Script Pokemod::Item::script() const +{ + return m_script; +} + +Pokemod::Item& Pokemod::Item::operator=(const Item& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(sellable); + COPY(type); + COPY(price); + COPY(description); + COPY(script); + return *this; +} diff --git a/sigmod/Item.h b/sigmod/Item.h new file mode 100644 index 00000000..01583ef9 --- /dev/null +++ b/sigmod/Item.h @@ -0,0 +1,71 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_ITEM__ +#define __POKEMOD_ITEM__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Item : public Object +{ + Q_OBJECT + + public: + Item(const Item& item); + Item(const Pokemod* parent, const int id); + Item(const Item& item, const Pokemod* parent, const int id); + Item(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~Item(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setSellable(const bool sellable); + void setType(const int type); + void setPrice(const int price); + void setDescription(const QString& description); + void setScript(const Script& script); + + QString name() const; + bool sellable() const; + int type() const; + int price() const; + QString description() const; + Script script() const; + + Item& operator=(const Item& rhs); + private: + QString m_name; + bool m_sellable; + int m_type; + int m_price; + QString m_description; + Script m_script; +}; +} + +#endif diff --git a/sigmod/ItemType.cpp b/sigmod/ItemType.cpp new file mode 100644 index 00000000..7c5ee9f1 --- /dev/null +++ b/sigmod/ItemType.cpp @@ -0,0 +1,135 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "ItemType.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +QStringList Pokemod::ItemType::CountStr = QStringList() << "Distinct" << "Total"; + +Pokemod::ItemType::ItemType(const ItemType& itemType) : + Object(itemType.parent(), itemType.id()) +{ + *this = itemType; +} + +Pokemod::ItemType::ItemType(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_computer(0), + m_player(1), + m_count(Distinct) +{ +} + +Pokemod::ItemType::ItemType(const ItemType& itemType, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = itemType; +} + +Pokemod::ItemType::ItemType(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::ItemType::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setPlayer, player); + TEST_END(); +} + +void Pokemod::ItemType::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(computer); + LOAD(player); + LOAD(count); +} + +QDomElement Pokemod::ItemType::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(computer); + SAVE(player); + SAVE(count); + return xml; +} + +void Pokemod::ItemType::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::ItemType::setComputer(const int computer) +{ + CHECK(computer); +} + +void Pokemod::ItemType::setPlayer(const int player) +{ + if (!player) + emit(error(bounds("player"))); + else + CHECK(player); +} + +void Pokemod::ItemType::setCount(const Count count) +{ + CHECK(count); +} + +QString Pokemod::ItemType::name() const +{ + return m_name; +} + +int Pokemod::ItemType::computer() const +{ + return m_computer; +} + +int Pokemod::ItemType::player() const +{ + return m_player; +} + +Pokemod::ItemType::Count Pokemod::ItemType::count() const +{ + return m_count; +} + +Pokemod::ItemType& Pokemod::ItemType::operator=(const ItemType& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(computer); + COPY(player); + COPY(count); + return *this; +} diff --git a/sigmod/ItemType.h b/sigmod/ItemType.h new file mode 100644 index 00000000..15b16704 --- /dev/null +++ b/sigmod/ItemType.h @@ -0,0 +1,72 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_ITEMTYPE__ +#define __POKEMOD_ITEMTYPE__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT ItemType : public Object +{ + Q_OBJECT + Q_ENUMS(Count) + + public: + enum Count + { + Distinct = 0, + Total = 1 + }; + static QStringList CountStr; + + ItemType(const ItemType& itemType); + ItemType(const Pokemod* parent, const int id); + ItemType(const ItemType& itemType, const Pokemod* parent, const int id); + ItemType(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setComputer(const int computer); + void setPlayer(const int player); + void setCount(const Count count); + + QString name() const; + int computer() const; + int player() const; + Count count() const; + + ItemType& operator=(const ItemType& rhs); + private: + QString m_name; + int m_computer; + int m_player; + Count m_count; +}; +} +Q_DECLARE_METATYPE(Pokemod::ItemType::Count) + +#endif diff --git a/sigmod/Macros.h b/sigmod/Macros.h new file mode 100644 index 00000000..bfd4f6c6 --- /dev/null +++ b/sigmod/Macros.h @@ -0,0 +1,112 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MACROS__ +#define __POKEMOD_MACROS__ + +#ifdef MAKE_POKEMOD_LIB + +// TODO: The macros should probably be replaced by protected members of Object + +#define LOAD_ID() \ + int newId = id; \ + if ((id == -1) && xml.hasAttribute("id")) \ + newId = xml.attribute("id", "-1").toInt(); \ + setId(newId) +#define LOAD_BEGIN() clear() +#define LOAD(variable) loadValue(xml.firstChildElement(#variable), &m_##variable) +#define LOAD_ARRAY(variable) loadArray(xml.firstChildElement(#variable), &m_##variable) +#define LOAD_LIST(variable) loadList(xml.firstChildElement(#variable), &m_##variable) +#define LOAD_MATRIX(variable) loadMatrix(xml.firstChildElement(#variable), &m_##variable) +#define LOAD_Rules() m_rules->load(xml.firstChildElement("Rules")) +#define LOAD_SUB(setter, class) \ + QDomElement xml_##class = xml.firstChildElement(#class); \ + while (!xml_##class.isNull()) \ + { \ + setter(xml_##class); \ + xml_##class = xml_##class.nextSiblingElement(#class); \ + } + +#define SAVE_CREATE() \ + QDomElement xml = QDomDocument().createElement(className()); \ + xml.setAttribute("id", id()) +#define SAVE(variable) xml.appendChild(saveValue(#variable, m_##variable)) +#define SAVE_ARRAY(variable) xml.appendChild(saveArray(#variable, m_##variable)) +#define SAVE_LIST(variable) xml.appendChild(saveList(#variable, m_##variable)) +#define SAVE_MATRIX(variable) xml.appendChild(saveMatrix(#variable, m_##variable)) +#define SAVE_Rules(variable) xml.appendChild(m_##variable->save()) +#define SAVE_SUB(class, variable) \ + foreach (class* sub, m_##variable) \ + xml.appendChild(sub->save()) + +#define COPY(variable) m_##variable = rhs.m_##variable +#define COPY_Rules(variable) *m_##variable = *rhs.m_##variable +#define COPY_SUB(class, variable) \ + foreach (class* subclass, rhs.m_##variable) \ + m_##variable.append(new class(*subclass, this, subclass->id())) + +#define TEST_BEGIN() \ + connect(this, SIGNAL(warning(QString)), SIGNAL(valWarning(QString))); \ + connect(this, SIGNAL(error(QString)), SIGNAL(valError(QString))); \ + emit(valMessage(QString("++%1 (%2)").arg(className()).arg(id()))) +#define TEST_END() \ + emit(valMessage(QString("--%1 (%2)").arg(className()).arg(id()))); \ + disconnect(this, SIGNAL(warning(QString)), this, SIGNAL(valWarning(QString))); \ + disconnect(this, SIGNAL(error(QString)), this, SIGNAL(valError(QString))) +#define TEST(setter, variable) setter(m_##variable) +#define TEST_ARRAY(setter, variable, size) \ + for (int i = 0; i < size; ++i) \ + setter(m_##variable[i]) +#define TEST_LIST(setter, variable) \ + foreach (int variable, m_##variable) \ + setter(variable, true) +#define TEST_MATRIX(setter, variable) \ + for (int i = 0; i < m_##variable.height(); ++i) \ + { \ + for (int j = 0; j < m_##variable.width(); ++j) \ + setter(i, j, m_##variable(i, j)); \ + } +#define TEST_CHILD(object) \ + connect(object, SIGNAL(valMessage(QString)), this, SIGNAL(valMessage(QString))); \ + connect(object, SIGNAL(valWarning(QString)), this, SIGNAL(valWarning(QString))); \ + connect(object, SIGNAL(valError(QString)), this, SIGNAL(valError(QString))); \ + object->validate(); \ + disconnect(object, SIGNAL(valMessage(QString)), this, SIGNAL(valMessage(QString))); \ + disconnect(object, SIGNAL(valWarning(QString)), this, SIGNAL(valWarning(QString))); \ + disconnect(object, SIGNAL(valError(QString)), this, SIGNAL(valError(QString))) +#define TEST_SUB_BEGIN(type, variable) \ + foreach (type* object, m_##variable) \ + { \ + TEST_CHILD(object) +#define TEST_SUB(name, value) TEST_SUB_RAW(value, name, value) +#define TEST_SUB_RAW(checking, name, value) \ + if (checking##Checker.contains(object->value())) \ + emit(error(subclass(name, object->id()))); \ + checking##Checker.insert(object->value()) +#define TEST_SUB_END() } + +#define CHECK(variable) CHECK_ARRAY(variable, variable) +#define CHECK_ARRAY(variable, value) \ + if (m_##variable != value) \ + { \ + m_##variable = value; \ + emit(changed()); \ + } + +#endif + +#endif diff --git a/sigmod/Map.cpp b/sigmod/Map.cpp new file mode 100644 index 00000000..6cb92154 --- /dev/null +++ b/sigmod/Map.cpp @@ -0,0 +1,573 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Map.h" + +// Pokemod includes +#include "Macros.h" +#include "MapEffect.h" +#include "MapTrainer.h" +#include "MapWarp.h" +#include "MapWildList.h" +#include "Pokemod.h" + +// Qt includes +#include <QtCore/QSet> + +const QStringList Pokemod::Map::TypeStr = QStringList() << "Outdoor" << "Dungeon" << "Building"; + +Pokemod::Map::Map(const Map& map) : + Object(map.parent(), map.id()) +{ + *this = map; +} + +Pokemod::Map::Map(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_flyWarp(-1), + m_type(Outdoor) +{ +} + +Pokemod::Map::Map(const Map& map, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = map; +} + +Pokemod::Map::Map(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::Map::~Map() +{ + clear(); +} + +void Pokemod::Map::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setFlyWarp, flyWarp); + TEST(setType, type); + TEST_MATRIX(setTile, map); + QSet<int> idChecker; + QSet<QString> nameChecker; + if (!effectCount()) + emit(warning("There are no effects")); + TEST_SUB_BEGIN(MapEffect, effects); + TEST_SUB("effect", id); + TEST_SUB("effect", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!trainerCount()) + emit(warning("There are no trainers")); + TEST_SUB_BEGIN(MapTrainer, trainers); + TEST_SUB("trainer", id); + TEST_SUB("trainer", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!warpCount()) + emit(error("There are no warps")); + TEST_SUB_BEGIN(MapWarp, warps); + TEST_SUB("warp", id); + TEST_SUB("warp", name); + TEST_SUB_END(); + idChecker.clear(); + if (!wildListCount()) + emit(warning("There are no wild lists")); + TEST_SUB_BEGIN(MapWildList, wildLists); + TEST_SUB("wild list", id); + TEST_SUB_END(); + TEST_END(); +} + +void Pokemod::Map::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(flyWarp); + LOAD(type); + LOAD_MATRIX(map); + LOAD_SUB(newEffect, MapEffect); + LOAD_SUB(newTrainer, MapTrainer); + LOAD_SUB(newWarp, MapWarp); + LOAD_SUB(newWildList, MapWildList); +} + +QDomElement Pokemod::Map::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(flyWarp); + SAVE(type); + SAVE_MATRIX(map); + SAVE_SUB(MapEffect, effects); + SAVE_SUB(MapTrainer, trainers); + SAVE_SUB(MapWarp, warps); + SAVE_SUB(MapWildList, wildLists); + return xml; +} + +void Pokemod::Map::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Map::setFlyWarp(const int flyWarp) +{ + if ((flyWarp != -1) && (warpIndex(flyWarp) == INT_MAX)) + emit(error(bounds("flyWarp"))); + else + CHECK(flyWarp); +} + +void Pokemod::Map::setType(const Type type) +{ + CHECK(type); +} + +QString Pokemod::Map::name() const +{ + return m_name; +} + +int Pokemod::Map::flyWarp() const +{ + return m_flyWarp; +} + +Pokemod::Map::Type Pokemod::Map::type() const +{ + return m_type; +} + +void Pokemod::Map::setTile(const int row, const int column, const int tile) +{ + if (qobject_cast<const Pokemod*>(pokemod())->tileIndex(tile) == INT_MAX) + emit(error(bounds("tile"))); + else + m_map.set(row, column, tile); +} + +void Pokemod::Map::insertColumn(const int column) +{ + m_map.insertColumn(column, 0); +} + +void Pokemod::Map::insertRow(const int row) +{ + m_map.insertRow(row, 0); +} + +void Pokemod::Map::addColumn() +{ + m_map.addColumn(0); +} + +void Pokemod::Map::addRow() +{ + m_map.addRow(0); +} + +void Pokemod::Map::deleteColumn(const int column) +{ + m_map.deleteColumn(column); +} + +void Pokemod::Map::deleteRow(const int row) +{ + m_map.deleteRow(row); +} + +const Pokemod::Matrix<int>* Pokemod::Map::map() const +{ + return &m_map; +} + +Pokemod::Matrix<int>* Pokemod::Map::map() +{ + return &m_map; +} + +int Pokemod::Map::tile(const int row, const int column) const +{ + return m_map.at(row, column); +} + +int Pokemod::Map::width() const +{ + return m_map.width(); +} + +int Pokemod::Map::height() const +{ + return m_map.height(); +} + +QPoint Pokemod::Map::size() const +{ + return m_map.size(); +} + +const Pokemod::MapEffect* Pokemod::Map::effect(const int index) const +{ + Q_ASSERT(index < effectCount()); + return m_effects.at(index); +} + +Pokemod::MapEffect* Pokemod::Map::effect(const int index) +{ + Q_ASSERT(index < effectCount()); + return m_effects[index]; +} + +const Pokemod::MapEffect* Pokemod::Map::effectById(const int index) const +{ + return effect(effectIndex(index)); +} + +Pokemod::MapEffect* Pokemod::Map::effectById(const int index) +{ + return effect(effectIndex(index)); +} + +int Pokemod::Map::effectIndex(const int id) const +{ + for (int i = 0; i < effectCount(); ++i) + { + if (m_effects[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Map::effectCount() const +{ + return m_effects.size(); +} + +Pokemod::MapEffect* Pokemod::Map::newEffect() +{ + return newEffect(new MapEffect(this, newEffectId())); +} + +Pokemod::MapEffect* Pokemod::Map::newEffect(const QDomElement& xml) +{ + return newEffect(new MapEffect(xml, this, newEffectId())); +} + +Pokemod::MapEffect* Pokemod::Map::newEffect(const MapEffect& effect) +{ + return newEffect(new MapEffect(effect, this, newEffectId())); +} + +Pokemod::MapEffect* Pokemod::Map::newEffect(MapEffect* effect) +{ + m_effects.append(effect); + return effect; +} + +void Pokemod::Map::deleteEffect(const int index) +{ + Q_ASSERT(index < effectCount()); + delete m_effects[index]; + m_effects.removeAt(index); +} + +void Pokemod::Map::deleteEffectById(const int id) +{ + deleteEffect(effectIndex(id)); +} + +int Pokemod::Map::newEffectId() const +{ + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::MapTrainer* Pokemod::Map::trainer(const int index) const +{ + Q_ASSERT(index < trainerCount()); + return m_trainers.at(index); +} + +Pokemod::MapTrainer* Pokemod::Map::trainer(const int index) +{ + Q_ASSERT(index < trainerCount()); + return m_trainers[index]; +} + +const Pokemod::MapTrainer* Pokemod::Map::trainerById(const int id) const +{ + return trainer(trainerIndex(id)); +} + +Pokemod::MapTrainer* Pokemod::Map::trainerById(const int id) +{ + return trainer(trainerIndex(id)); +} + +int Pokemod::Map::trainerIndex(const int id) const +{ + for (int i = 0; i < trainerCount(); ++i) + { + if (m_trainers[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Map::trainerCount() const +{ + return m_trainers.size(); +} + +Pokemod::MapTrainer* Pokemod::Map::newTrainer() +{ + return newTrainer(new MapTrainer(this, newTrainerId())); +} + +Pokemod::MapTrainer* Pokemod::Map::newTrainer(const QDomElement& xml) +{ + return newTrainer(new MapTrainer(xml, this, newTrainerId())); +} + +Pokemod::MapTrainer* Pokemod::Map::newTrainer(const MapTrainer& trainer) +{ + return newTrainer(new MapTrainer(trainer, this, newTrainerId())); +} + +Pokemod::MapTrainer* Pokemod::Map::newTrainer(MapTrainer* trainer) +{ + m_trainers.append(trainer); + return trainer; +} + +void Pokemod::Map::deleteTrainer(const int index) +{ + Q_ASSERT(index < trainerCount()); + delete m_trainers[index]; + m_trainers.removeAt(index); +} + +void Pokemod::Map::deleteTrainerById(const int id) +{ + deleteTrainer(trainerIndex(id)); +} + +int Pokemod::Map::newTrainerId() const +{ + int i = 0; + while ((i < trainerCount()) && (trainerIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::MapWarp* Pokemod::Map::warp(const int index) const +{ + Q_ASSERT(index < warpCount()); + return m_warps.at(index); +} + +Pokemod::MapWarp* Pokemod::Map::warp(const int index) +{ + Q_ASSERT(index < warpCount()); + return m_warps[index]; +} + +const Pokemod::MapWarp* Pokemod::Map::warpById(const int id) const +{ + return warp(warpIndex(id)); +} + +Pokemod::MapWarp* Pokemod::Map::warpById(const int id) +{ + return warp(warpIndex(id)); +} + +int Pokemod::Map::warpIndex(const int id) const +{ + for (int i = 0; i < warpCount(); ++i) + { + if (m_warps[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Map::warpCount() const +{ + return m_warps.size(); +} + +Pokemod::MapWarp* Pokemod::Map::newWarp() +{ + return newWarp(new MapWarp(this, newWarpId())); +} + +Pokemod::MapWarp* Pokemod::Map::newWarp(const QDomElement& xml) +{ + return newWarp(new MapWarp(xml, this, newWarpId())); +} + +Pokemod::MapWarp* Pokemod::Map::newWarp(const MapWarp& warp) +{ + return newWarp(new MapWarp(warp, this, newWarpId())); +} + +Pokemod::MapWarp* Pokemod::Map::newWarp(MapWarp* warp) +{ + m_warps.append(warp); + return warp; +} + +void Pokemod::Map::deleteWarp(const int index) +{ + Q_ASSERT(index < warpCount()); + delete m_warps[index]; + m_warps.removeAt(index); +} + +void Pokemod::Map::deleteWarpById(const int id) +{ + deleteWarp(warpIndex(id)); +} + +int Pokemod::Map::newWarpId() const +{ + int i = 0; + while ((i < warpCount()) && (warpIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::MapWildList* Pokemod::Map::wildList(const int index) const +{ + Q_ASSERT(index < wildListCount()); + return m_wildLists.at(index); +} + +Pokemod::MapWildList* Pokemod::Map::wildList(const int index) +{ + Q_ASSERT(index < wildListCount()); + return m_wildLists[index]; +} + +const Pokemod::MapWildList* Pokemod::Map::wildListById(const int id) const +{ + return wildList(wildListIndex(id)); +} + +Pokemod::MapWildList* Pokemod::Map::wildListById(const int id) +{ + return wildList(wildListIndex(id)); +} + +int Pokemod::Map::wildListIndex(const int id) const +{ + for (int i = 0; i < wildListCount(); ++i) + { + if (m_wildLists[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Map::wildListCount() const +{ + return m_wildLists.size(); +} + +Pokemod::MapWildList* Pokemod::Map::newWildList() +{ + return newWildList(new MapWildList(this, newWildListId())); +} + +Pokemod::MapWildList* Pokemod::Map::newWildList(const QDomElement& xml) +{ + return newWildList(new MapWildList(xml, this, newWildListId())); +} + +Pokemod::MapWildList* Pokemod::Map::newWildList(const MapWildList& wildList) +{ + return newWildList(new MapWildList(wildList, this, newWildListId())); +} + +Pokemod::MapWildList* Pokemod::Map::newWildList(MapWildList* wildList) +{ + m_wildLists.append(wildList); + return wildList; +} + +void Pokemod::Map::deleteWildList(const int index) +{ + Q_ASSERT(index < wildListCount()); + delete m_wildLists[index]; + m_wildLists.removeAt(index); +} + +void Pokemod::Map::deleteWildListById(const int id) +{ + deleteWildList(wildListIndex(id)); +} + +int Pokemod::Map::newWildListId() const +{ + int i = 0; + while ((i < warpCount()) && (warpIndex(i) != INT_MAX)) + ++i; + return i; +} + +Pokemod::Map& Pokemod::Map::operator=(const Map& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(name); + COPY(flyWarp); + COPY(type); + COPY(map); + COPY_SUB(MapEffect, effects); + COPY_SUB(MapTrainer, trainers); + COPY_SUB(MapWarp, warps); + COPY_SUB(MapWildList, wildLists); + return *this; +} + +void Pokemod::Map::clear() +{ + while (effectCount()) + deleteEffect(0); + while (trainerCount()) + deleteTrainer(0); + while (warpCount()) + deleteWarp(0); + while (wildListCount()) + deleteWildList(0); +} diff --git a/sigmod/Map.h b/sigmod/Map.h new file mode 100644 index 00000000..34b102df --- /dev/null +++ b/sigmod/Map.h @@ -0,0 +1,161 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MAP__ +#define __POKEMOD_MAP__ + +// Pokemod includes +#include "Matrix.h" +#include "Object.h" + +// Qt includes +#include <QtCore/QList> + +namespace Pokemod +{ +// Forward declarations +class MapEffect; +class MapTrainer; +class MapWarp; +class MapWildList; +class Pokemod; + +class POKEMOD_EXPORT Map : public Object +{ + Q_OBJECT + Q_ENUMS(Type) + + public: + enum Type + { + Outdoor = 0, + Dungeon = 1, + Building = 2 + }; + static const QStringList TypeStr; + + Map(const Map& map); + Map(const Pokemod* parent, const int id); + Map(const Map& map, const Pokemod* parent, const int id); + Map(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~Map(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setFlyWarp(const int flyWarp); + void setType(const Type type); + + QString name() const; + int flyWarp() const; + Type type() const; + + void setTile(const int row, const int column, const int tile); + void insertColumn(const int column); + void insertRow(const int row); + void addColumn(); + void addRow(); + void deleteColumn(const int column); + void deleteRow(const int row); + + const Matrix<int>* map() const; + Matrix<int>* map(); + int tile(const int row, const int column) const; + int width() const; + int height() const; + QPoint size() const; + + const MapEffect* effect(const int index) const; + MapEffect* effect(const int index); + const MapEffect* effectById(const int id) const; + MapEffect* effectById(const int id); + int effectIndex(const int id) const; + int effectCount() const; + MapEffect* newEffect(); + MapEffect* newEffect(const QDomElement& xml); + MapEffect* newEffect(const MapEffect& effect); + void deleteEffect(const int index); + void deleteEffectById(const int id); + + const MapTrainer* trainer(const int index) const; + MapTrainer* trainer(const int index); + const MapTrainer* trainerById(const int id) const; + MapTrainer* trainerById(const int id); + int trainerIndex(const int id) const; + int trainerCount() const; + MapTrainer* newTrainer(); + MapTrainer* newTrainer(const QDomElement& xml); + MapTrainer* newTrainer(const MapTrainer& trainer); + void deleteTrainer(const int index); + void deleteTrainerById(const int id); + + const MapWarp* warp(const int index) const; + MapWarp* warp(const int index); + const MapWarp* warpById(const int id) const; + MapWarp* warpById(const int id); + int warpIndex(const int id) const; + int warpCount() const; + MapWarp* newWarp(); + MapWarp* newWarp(const QDomElement& xml); + MapWarp* newWarp(const MapWarp& warp); + void deleteWarp(const int index); + void deleteWarpById(const int id); + + const MapWildList* wildList(const int index) const; + MapWildList* wildList(const int index); + const MapWildList* wildListById(const int id) const; + MapWildList* wildListById(const int id); + int wildListIndex(const int id) const; + int wildListCount() const; + MapWildList* newWildList(); + MapWildList* newWildList(const QDomElement& xml); + MapWildList* newWildList(const MapWildList& wildList); + void deleteWildList(const int index); + void deleteWildListById(const int id); + + Map& operator=(const Map& rhs); + private: + int newEffectId() const; + MapEffect* newEffect(MapEffect* effect); + + int newTrainerId() const; + MapTrainer* newTrainer(MapTrainer* trainer); + + int newWarpId() const; + MapWarp* newWarp(MapWarp* warp); + + int newWildListId() const; + MapWildList* newWildList(MapWildList* wildList); + + void clear(); + + QString m_name; + int m_flyWarp; + Type m_type; + Matrix<int> m_map; + QList<MapEffect*> m_effects; + QList<MapTrainer*> m_trainers; + QList<MapWarp*> m_warps; + QList<MapWildList*> m_wildLists; +}; +} +Q_DECLARE_METATYPE(Pokemod::Map::Type) + +#endif diff --git a/sigmod/MapEffect.cpp b/sigmod/MapEffect.cpp new file mode 100644 index 00000000..558596f5 --- /dev/null +++ b/sigmod/MapEffect.cpp @@ -0,0 +1,152 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapEffect.h" + +// Pokemod includes +#include "Macros.h" +#include "Map.h" +#include "Pokemod.h" + +Pokemod::MapEffect::MapEffect(const MapEffect& effect) : + Object(effect.parent(), effect.id()) +{ + *this = effect; +} + +Pokemod::MapEffect::MapEffect(const Map* parent, const int id) : + Object(parent, id), + m_name(""), + m_coordinate(0, 0), + m_skin(-1), + m_isGhost(false), + m_script("", "") +{ +} + +Pokemod::MapEffect::MapEffect(const MapEffect& effect, const Map* parent, const int id) : + Object(parent, id) +{ + *this = effect; +} + +Pokemod::MapEffect::MapEffect(const QDomElement& xml, const Map* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::MapEffect::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setCoordinate, coordinate); + TEST(setSkin, skin); + TEST_END(); +} + +void Pokemod::MapEffect::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(coordinate); + LOAD(skin); + LOAD(isGhost); + LOAD(script); +} + +QDomElement Pokemod::MapEffect::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(coordinate); + SAVE(skin); + SAVE(isGhost); + SAVE(script); + return xml; +} + +void Pokemod::MapEffect::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::MapEffect::setCoordinate(const QPoint& coordinate) +{ + if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) + emit(error(bounds("coordinate"))); + else + CHECK(coordinate); +} + +void Pokemod::MapEffect::setSkin(const int skin) +{ + if (qobject_cast<const Pokemod*>(pokemod())->skinIndex(skin) == INT_MAX) + emit(error(bounds("skin"))); + else + CHECK(skin); +} + +void Pokemod::MapEffect::setIsGhost(const bool isGhost) +{ + CHECK(isGhost); +} + +void Pokemod::MapEffect::setScript(const Script& script) +{ + CHECK(script); +} + +QString Pokemod::MapEffect::name() const +{ + return m_name; +} + +QPoint Pokemod::MapEffect::coordinate() const +{ + return m_coordinate; +} + +int Pokemod::MapEffect::skin() const +{ + return m_skin; +} + +bool Pokemod::MapEffect::isGhost() const +{ + return m_isGhost; +} + +Pokemod::Script Pokemod::MapEffect::script() const +{ + return m_script; +} + +Pokemod::MapEffect& Pokemod::MapEffect::operator=(const MapEffect& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(coordinate); + COPY(skin); + COPY(isGhost); + COPY(script); + return *this; +} diff --git a/sigmod/MapEffect.h b/sigmod/MapEffect.h new file mode 100644 index 00000000..3c4d3f4a --- /dev/null +++ b/sigmod/MapEffect.h @@ -0,0 +1,70 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MAPEFFECT__ +#define __POKEMOD_MAPEFFECT__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +// Qt includes +#include <QtCore/QPoint> + +namespace Pokemod +{ +// Forward declarations +class Map; + +class POKEMOD_EXPORT MapEffect : public Object +{ + Q_OBJECT + + public: + MapEffect(const MapEffect& effect); + MapEffect(const Map* parent, const int id); + MapEffect(const MapEffect& effect, const Map* parent, const int id); + MapEffect(const QDomElement& xml, const Map* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setCoordinate(const QPoint& coordinate); + void setSkin(const int skin); + void setIsGhost(const bool isGhost); + void setScript(const Script& script); + + QString name() const; + QPoint coordinate() const; + int skin() const; + bool isGhost() const; + Script script() const; + + MapEffect& operator=(const MapEffect& rhs); + private: + QString m_name; + QPoint m_coordinate; + int m_skin; + bool m_isGhost; + Script m_script; +}; +} + +#endif diff --git a/sigmod/MapTrainer.cpp b/sigmod/MapTrainer.cpp new file mode 100644 index 00000000..4df1cbed --- /dev/null +++ b/sigmod/MapTrainer.cpp @@ -0,0 +1,277 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapTrainer.h" + +// Pokemod includes +#include "Macros.h" +#include "Map.h" +#include "MapTrainerTeamMember.h" +#include "Pokemod.h" +#include "Rules.h" + +// Qt includes +#include <QtCore/QSet> + +Pokemod::MapTrainer::MapTrainer(const MapTrainer& trainer) : + Object(trainer.parent(), trainer.id()) +{ + *this = trainer; +} + +Pokemod::MapTrainer::MapTrainer(const Map* parent, const int id) : + Object(parent, id), + m_name(""), + m_trainerClass(INT_MAX), + m_coordinate(0, 0), + m_numberFight(1), + m_script("", ""), + m_leadTeamMember(INT_MAX) +{ +} + +Pokemod::MapTrainer::MapTrainer(const MapTrainer& trainer, const Map* parent, const int id) : + Object(parent, id) +{ + *this = trainer; +} + +Pokemod::MapTrainer::MapTrainer(const QDomElement& xml, const Map* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::MapTrainer::~MapTrainer() +{ + clear(); +} + +void Pokemod::MapTrainer::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setTrainerClass, trainerClass); + TEST(setCoordinate, coordinate); + TEST(setNumberFight, numberFight); + TEST(setLeadTeamMember, leadTeamMember); + if (!teamMemberCount()) + emit(error("There are no team members")); + QSet<int> idChecker; + TEST_SUB_BEGIN(MapTrainerTeamMember, teamMembers); + TEST_SUB("team member", id); + TEST_SUB_END(); + TEST_END(); +} + +void Pokemod::MapTrainer::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(trainerClass); + LOAD(coordinate); + LOAD(numberFight); + LOAD(script); + LOAD_SUB(newTeamMember, MapTrainerTeamMember); + LOAD(leadTeamMember); +} + +QDomElement Pokemod::MapTrainer::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(trainerClass); + SAVE(coordinate); + SAVE(numberFight); + SAVE(script); + SAVE_SUB(MapTrainerTeamMember, teamMembers); + return xml; +} + +void Pokemod::MapTrainer::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::MapTrainer::setTrainerClass(const int trainerClass) +{ + if (qobject_cast<const Pokemod*>(pokemod())->trainerIndex(trainerClass) == INT_MAX) + emit(error(bounds("trainerClass"))); + else + CHECK(trainerClass); +} + +void Pokemod::MapTrainer::setCoordinate(const QPoint& coordinate) +{ + if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) + emit(error(bounds("coordinate"))); + else + CHECK(coordinate); +} + +void Pokemod::MapTrainer::setNumberFight(const int numberFight) +{ + if (!numberFight || (qobject_cast<const Pokemod*>(pokemod())->rules()->maxFight() < numberFight)) + emit(error(bounds("numberFight"))); + else + CHECK(numberFight); +} + +void Pokemod::MapTrainer::setScript(const Script& script) +{ + CHECK(script); +} + +void Pokemod::MapTrainer::setLeadTeamMember(const int leadTeamMember) +{ + if (teamMemberIndex(leadTeamMember) == INT_MAX) + emit(error(bounds("leadTeamMember"))); + else + CHECK(leadTeamMember); +} + +QString Pokemod::MapTrainer::name() const +{ + return m_name; +} + +int Pokemod::MapTrainer::trainerClass() const +{ + return m_trainerClass; +} + +QPoint Pokemod::MapTrainer::coordinate() const +{ + return m_coordinate; +} + +int Pokemod::MapTrainer::numberFight() const +{ + return m_numberFight; +} + +Pokemod::Script Pokemod::MapTrainer::script() const +{ + return m_script; +} + +int Pokemod::MapTrainer::leadTeamMember() const +{ + return m_leadTeamMember; +} + +const Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::teamMember(const int index) const +{ + Q_ASSERT(index < teamMemberCount()); + return m_teamMembers.at(index); +} + +Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::teamMember(const int index) +{ + Q_ASSERT(index < teamMemberCount()); + return m_teamMembers[index]; +} + +const Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::teamMemberById(const int id) const +{ + return teamMember(teamMemberIndex(id)); +} + +Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::teamMemberById(const int id) +{ + return teamMember(teamMemberIndex(id)); +} + +int Pokemod::MapTrainer::teamMemberIndex(const int id) const +{ + for (int i = 0; i < teamMemberCount(); ++i) + { + if (m_teamMembers[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::MapTrainer::teamMemberCount() const +{ + return m_teamMembers.size(); +} + +Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::newTeamMember() +{ + return newTeamMember(new MapTrainerTeamMember(this, newTeamMemberId())); +} + +Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::newTeamMember(const QDomElement& xml) +{ + return newTeamMember(new MapTrainerTeamMember(xml, this, newTeamMemberId())); +} + +Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::newTeamMember(const MapTrainerTeamMember& teamMember) +{ + return newTeamMember(new MapTrainerTeamMember(teamMember, this, newTeamMemberId())); +} + +Pokemod::MapTrainerTeamMember* Pokemod::MapTrainer::newTeamMember(MapTrainerTeamMember* teamMember) +{ + m_teamMembers.append(teamMember); + return teamMember; +} + +void Pokemod::MapTrainer::deleteTeamMember(const int index) +{ + Q_ASSERT(index < teamMemberCount()); + delete m_teamMembers[index]; + m_teamMembers.removeAt(index); +} + +void Pokemod::MapTrainer::deleteTeamMemberById(const int id) +{ + deleteTeamMember(teamMemberIndex(id)); +} + +int Pokemod::MapTrainer::newTeamMemberId() const +{ + int i = 0; + while ((i < teamMemberCount()) && (teamMemberIndex(i) != INT_MAX)) + ++i; + return i; +} + +Pokemod::MapTrainer& Pokemod::MapTrainer::operator=(const MapTrainer& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(name); + COPY(trainerClass); + COPY(coordinate); + COPY(numberFight); + COPY(script); + COPY(leadTeamMember); + COPY_SUB(MapTrainerTeamMember, teamMembers); + return *this; +} + +void Pokemod::MapTrainer::clear() +{ + while (teamMemberCount()) + deleteTeamMember(0); +} diff --git a/sigmod/MapTrainer.h b/sigmod/MapTrainer.h new file mode 100644 index 00000000..f77d0a97 --- /dev/null +++ b/sigmod/MapTrainer.h @@ -0,0 +1,94 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MAPTRAINER__ +#define __POKEMOD_MAPTRAINER__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +// Qt includes +#include <QtCore/QList> +#include <QtCore/QPoint> + +namespace Pokemod +{ +// Forward declarations +class Map; +class MapTrainerTeamMember; + +class POKEMOD_EXPORT MapTrainer : public Object +{ + Q_OBJECT + + public: + MapTrainer(const MapTrainer& trainer); + MapTrainer(const Map* parent, const int id); + MapTrainer(const MapTrainer& trainer, const Map* parent, const int id); + MapTrainer(const QDomElement& xml, const Map* parent, const int id = -1); + ~MapTrainer(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setTrainerClass(const int trainerClass); + void setCoordinate(const QPoint& coordinate); + void setNumberFight(const int numberFight); + void setScript(const Script& script); + void setLeadTeamMember(const int leadTeamMember); + + QString name() const; + int trainerClass() const; + QPoint coordinate() const; + int numberFight() const; + Script script() const; + int leadTeamMember() const; + + const MapTrainerTeamMember* teamMember(const int index) const; + MapTrainerTeamMember* teamMember(const int index); + const MapTrainerTeamMember* teamMemberById(const int id) const; + MapTrainerTeamMember* teamMemberById(const int id); + int teamMemberIndex(const int id) const; + int teamMemberCount() const; + MapTrainerTeamMember* newTeamMember(); + MapTrainerTeamMember* newTeamMember(const QDomElement& xml); + MapTrainerTeamMember* newTeamMember(const MapTrainerTeamMember& teamMember); + void deleteTeamMember(const int index); + void deleteTeamMemberById(const int id); + + MapTrainer& operator=(const MapTrainer& rhs); + private: + int newTeamMemberId() const; + MapTrainerTeamMember* newTeamMember(MapTrainerTeamMember* teamMember); + + void clear(); + + QString m_name; + int m_trainerClass; + QPoint m_coordinate; + int m_numberFight; + Script m_script; + int m_leadTeamMember; + QList<MapTrainerTeamMember*> m_teamMembers; +}; +} + +#endif diff --git a/sigmod/MapTrainerTeamMember.cpp b/sigmod/MapTrainerTeamMember.cpp new file mode 100644 index 00000000..d69411a5 --- /dev/null +++ b/sigmod/MapTrainerTeamMember.cpp @@ -0,0 +1,273 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapTrainerTeamMember.h" + +// Pokemod includes +#include "Item.h" +#include "Macros.h" +#include "MapTrainer.h" +#include "Pokemod.h" +#include "Rules.h" +#include "Species.h" +#include "SpeciesMove.h" + +// Qt includes +#include <QtCore/QSet> + +Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember) : + Object(teamMember.parent(), teamMember.id()) +{ + *this = teamMember; +} + +Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainer* parent, const int id) : + Object(parent, id), + m_species(INT_MAX), + m_level(INT_MAX) +{ +} + +Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const MapTrainerTeamMember& teamMember, const MapTrainer* parent, const int id) : + Object(parent, id) +{ + *this = teamMember; +} + +Pokemod::MapTrainerTeamMember::MapTrainerTeamMember(const QDomElement& xml, const MapTrainer* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::MapTrainerTeamMember::validate() +{ + TEST_BEGIN(); + TEST(setSpecies, species); + TEST(setLevel, level); + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxAbilities() < m_ability.size()) + emit(error("Too many abilities")); + TEST_LIST(setAbility, ability); + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxHeldItems() < m_item.size()) + emit(error("Too many held items")); + TEST_LIST(setItem, item); + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxMoves() < m_move.size()) + emit(error("Too many moves")); + TEST_LIST(setMove, move); + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxNatures() < m_nature.size()) + emit(error("Too many natures")); + TEST_LIST(setNature, nature); + TEST_END(); +} + +void Pokemod::MapTrainerTeamMember::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(species); + LOAD(level); + LOAD_LIST(ability); + LOAD_LIST(item); + LOAD_LIST(move); + LOAD_LIST(nature); +} + +QDomElement Pokemod::MapTrainerTeamMember::save() const +{ + SAVE_CREATE(); + SAVE(species); + SAVE(level); + SAVE_LIST(ability); + SAVE_LIST(item); + SAVE_LIST(move); + SAVE_LIST(nature); + return xml; +} + +void Pokemod::MapTrainerTeamMember::setSpecies(const int species) +{ + if (qobject_cast<const Pokemod*>(pokemod())->speciesIndex(species) == INT_MAX) + emit(error(bounds("species"))); + else + CHECK(species); +} + +void Pokemod::MapTrainerTeamMember::setLevel(const int level) +{ + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() < level) + emit(error(bounds("level"))); + else + CHECK(level); +} + +void Pokemod::MapTrainerTeamMember::setAbility(const int ability, const bool state) +{ + if (qobject_cast<const Pokemod*>(pokemod())->abilityIndex(ability) == INT_MAX) + emit(error(bounds("ability"))); + else if (state && !m_ability.contains(ability)) + { + if (m_ability.size() < qobject_cast<const Pokemod*>(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 (qobject_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) + emit(error(bounds("item"))); + else if (state && !m_item.contains(item)) + { + if (m_item.size() < qobject_cast<const Pokemod*>(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 (qobject_cast<const Pokemod*>(pokemod())->moveIndex(move) == INT_MAX) + emit(error(bounds("move"))); + else if (state && !m_move.contains(move)) + { + const Species* species = qobject_cast<const Pokemod*>(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() < qobject_cast<const Pokemod*>(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 (qobject_cast<const Pokemod*>(pokemod())->natureIndex(nature) == INT_MAX) + emit(error(bounds("nature"))); + else if (state && !m_nature.contains(nature)) + { + if (m_nature.size() < qobject_cast<const Pokemod*>(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); +} + +QList<int> Pokemod::MapTrainerTeamMember::abilities() const +{ + return m_ability; +} + +bool Pokemod::MapTrainerTeamMember::item(const int item) const +{ + return m_item.contains(item); +} + +QList<int> Pokemod::MapTrainerTeamMember::items() const +{ + return m_item; +} + +bool Pokemod::MapTrainerTeamMember::move(const int move) const +{ + return m_move.contains(move); +} + +QList<int> Pokemod::MapTrainerTeamMember::moves() const +{ + return m_move; +} + +bool Pokemod::MapTrainerTeamMember::nature(const int nature) const +{ + return m_nature.contains(nature); +} + +QList<int> Pokemod::MapTrainerTeamMember::natures() const +{ + return m_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; +} diff --git a/sigmod/MapTrainerTeamMember.h b/sigmod/MapTrainerTeamMember.h new file mode 100644 index 00000000..f396c041 --- /dev/null +++ b/sigmod/MapTrainerTeamMember.h @@ -0,0 +1,76 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MAPTRAINERTEAMMEMBER__ +#define __POKEMOD_MAPTRAINERTEAMMEMBER__ + +// Pokemod includes +#include "Object.h" + +// Qt includes +#include <QtCore/QList> + +namespace Pokemod +{ +// Forward dclarations +class MapTrainer; + +class POKEMOD_EXPORT MapTrainerTeamMember : public Object +{ + Q_OBJECT + + public: + MapTrainerTeamMember(const MapTrainerTeamMember& teamMember); + MapTrainerTeamMember(const MapTrainer* parent, const int id); + MapTrainerTeamMember(const MapTrainerTeamMember& teamMember, const MapTrainer* parent, const int id); + MapTrainerTeamMember(const QDomElement& xml, const MapTrainer* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setSpecies(const int species); + void setLevel(const int level); + void setAbility(const int ability, const bool state); + void setItem(const int item, const bool state); + void setMove(const int move, const bool state); + void setNature(const int nature, const bool state); + + int species() const; + int level() const; + bool ability(const int ability) const; + QList<int> abilities() const; + bool item(const int item) const; + QList<int> items() const; + bool move(const int move) const; + QList<int> moves() const; + bool nature(const int nature) const; + QList<int> natures() const; + + MapTrainerTeamMember& operator=(const MapTrainerTeamMember& p); + private: + int m_species; + int m_level; + QList<int> m_ability; + QList<int> m_item; + QList<int> m_move; + QList<int> m_nature; +}; +} + +#endif diff --git a/sigmod/MapWarp.cpp b/sigmod/MapWarp.cpp new file mode 100644 index 00000000..cc922a33 --- /dev/null +++ b/sigmod/MapWarp.cpp @@ -0,0 +1,173 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapWarp.h" + +// Pokemod includes +#include "Macros.h" +#include "Map.h" +#include "Pokemod.h" + +const QStringList Pokemod::MapWarp::TypeStr = QStringList() << "Door" << "Warp" << "Hole" << "Boundary"; + +Pokemod::MapWarp::MapWarp(const MapWarp& warp) : + Object(warp.parent(), warp.id()) +{ + *this = warp; +} + +Pokemod::MapWarp::MapWarp(const Map* parent, const int id) : + Object(parent, id), + m_name(""), + m_coordinate(0, 0), + m_type(Door), + m_toMap(INT_MAX), + m_toWarp(INT_MAX), + m_script("", "") +{ +} + +Pokemod::MapWarp::MapWarp(const MapWarp& warp, const Map* parent, const int id) : + Object(parent, id) +{ + *this = warp; +} + +Pokemod::MapWarp::MapWarp(const QDomElement& xml, const Map* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::MapWarp::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setToMap, toMap); + TEST(setToWarp, toWarp); + TEST_END(); +} + +void Pokemod::MapWarp::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(coordinate); + LOAD(type); + LOAD(toMap); + LOAD(toWarp); + LOAD(script); +} + +QDomElement Pokemod::MapWarp::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(coordinate); + SAVE(type); + SAVE(toMap); + SAVE(toWarp); + SAVE(script); + return xml; +} + +void Pokemod::MapWarp::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::MapWarp::setCoordinate(const QPoint& coordinate) +{ + if ((qobject_cast<const Map*>(parent())->width() <= coordinate.x()) || (qobject_cast<const Map*>(parent())->height() <= coordinate.y())) + emit(error(bounds("coordinate"))); + else + CHECK(coordinate); +} + +void Pokemod::MapWarp::setType(const Type type) +{ + CHECK(type); +} + +void Pokemod::MapWarp::setToMap(const int toMap) +{ + if (qobject_cast<const Pokemod*>(pokemod())->mapIndex(toMap) == INT_MAX) + emit(error(bounds("toMap"))); + else + CHECK(toMap); +} + +void Pokemod::MapWarp::setToWarp(const int toWarp) +{ + if (qobject_cast<const Pokemod*>(pokemod())->mapIndex(m_toMap) == INT_MAX) + emit(error(bounds("toMap"))); + else if (qobject_cast<const Pokemod*>(pokemod())->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) + emit(error(bounds("toWarp"))); + else + CHECK(toWarp); +} + +void Pokemod::MapWarp::setScript(const Script& script) +{ + CHECK(script); +} + +QString Pokemod::MapWarp::name() const +{ + return m_name; +} + +QPoint Pokemod::MapWarp::coordinate() const +{ + return m_coordinate; +} + +Pokemod::MapWarp::Type Pokemod::MapWarp::type() const +{ + return m_type; +} + +int Pokemod::MapWarp::toMap() const +{ + return m_toMap; +} + +int Pokemod::MapWarp::toWarp() const +{ + return m_toWarp; +} + +Pokemod::Script Pokemod::MapWarp::script() const +{ + return m_script; +} + +Pokemod::MapWarp& Pokemod::MapWarp::operator=(const MapWarp& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(coordinate); + COPY(type); + COPY(toMap); + COPY(toWarp); + COPY(script); + return *this; +} diff --git a/sigmod/MapWarp.h b/sigmod/MapWarp.h new file mode 100644 index 00000000..0df7016f --- /dev/null +++ b/sigmod/MapWarp.h @@ -0,0 +1,84 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MAPWARP__ +#define __POKEMOD_MAPWARP__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +// Qt includes +#include <QtCore/QPoint> + +namespace Pokemod +{ +// Forward declarations +class Map; + +class POKEMOD_EXPORT MapWarp : public Object +{ + Q_OBJECT + Q_ENUMS(Type) + + public: + enum Type + { + Door = 0, + Warp = 1, + Hole = 2, + Boundary = 3 + }; + static const QStringList TypeStr; + + MapWarp(const MapWarp& warp); + MapWarp(const Map* parent, const int id); + MapWarp(const MapWarp& warp, const Map* parent, const int id); + MapWarp(const QDomElement& xml, const Map* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setCoordinate(const QPoint& coordinate); + void setType(const Type type); + void setToMap(const int toMap); + void setToWarp(const int toWarp); + void setScript(const Script& script); + + QString name() const; + QPoint coordinate() const; + Type type() const; + int toMap() const; + int toWarp() const; + Script script() const; + + MapWarp& operator=(const MapWarp& rhs); + private: + QString m_name; + QPoint m_coordinate; + Type m_type; + int m_toMap; + int m_toWarp; + Script m_script; +}; +} +Q_DECLARE_METATYPE(Pokemod::MapWarp::Type) + +#endif diff --git a/sigmod/MapWildList.cpp b/sigmod/MapWildList.cpp new file mode 100644 index 00000000..30a7f56d --- /dev/null +++ b/sigmod/MapWildList.cpp @@ -0,0 +1,190 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapWildList.h" + +// Pokemod includes +#include "Macros.h" +#include "Map.h" +#include "MapWildListEncounter.h" + +// Qt includes +#include <QtCore/QSet> + +Pokemod::MapWildList::MapWildList(const MapWildList& wildList) : + Object(wildList.parent(), wildList.id()) +{ + *this = wildList; +} + +Pokemod::MapWildList::MapWildList(const Map* parent, const int id) : + Object(parent, id), + m_name("") +{ +} + +Pokemod::MapWildList::MapWildList(const MapWildList& wildList, const Map* parent, const int id) : + Object(parent, id) +{ + *this = wildList; +} + +Pokemod::MapWildList::MapWildList(const QDomElement& xml, const Map* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::MapWildList::~MapWildList() +{ + clear(); +} + +void Pokemod::MapWildList::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + if (!encounterCount()) + emit(error("There are no encounters")); + QSet<int> idChecker; + TEST_SUB_BEGIN(MapWildListEncounter, encounters); + TEST_SUB("encounter", id); + TEST_SUB_END(); + TEST_END(); +} + +void Pokemod::MapWildList::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD_SUB(newEncounter, MapWildListEncounter); +} + +QDomElement Pokemod::MapWildList::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE_SUB(MapWildListEncounter, encounters); + return xml; +} + +void Pokemod::MapWildList::setName(const QString& name) +{ + CHECK(name); +} + +QString Pokemod::MapWildList::name() const +{ + return m_name; +} + +const Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounter(const int index) const +{ + Q_ASSERT(index < encounterCount()); + return m_encounters.at(index); +} + +Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounter(const int index) +{ + Q_ASSERT(index < encounterCount()); + return m_encounters[index]; +} + +const Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounterById(const int id) const +{ + return encounter(encounterIndex(id)); +} + +Pokemod::MapWildListEncounter* Pokemod::MapWildList::encounterById(const int id) +{ + return encounter(encounterIndex(id)); +} + +int Pokemod::MapWildList::encounterIndex(const int id) const +{ + for (int i = 0; i < encounterCount(); ++i) + { + if (m_encounters[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::MapWildList::encounterCount() const +{ + return m_encounters.size(); +} + +Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter() +{ + return newEncounter(new MapWildListEncounter(this, newEncounterId())); +} + +Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter(const QDomElement& xml) +{ + return newEncounter(new MapWildListEncounter(xml, this, newEncounterId())); +} + +Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter(const MapWildListEncounter& encounter) +{ + return newEncounter(new MapWildListEncounter(encounter, this, newEncounterId())); +} + +Pokemod::MapWildListEncounter* Pokemod::MapWildList::newEncounter(MapWildListEncounter* encounter) +{ + m_encounters.append(encounter); + return encounter; +} + +void Pokemod::MapWildList::deleteEncounter(const int index) +{ + Q_ASSERT(index < encounterCount()); + delete m_encounters[index]; + m_encounters.removeAt(index); +} + +void Pokemod::MapWildList::deleteEncounterById(const int id) +{ + deleteEncounter(encounterIndex(id)); +} + +int Pokemod::MapWildList::newEncounterId() const +{ + int i = 0; + while ((i < encounterCount()) && (encounterIndex(i) != INT_MAX)) + ++i; + return i; +} + +Pokemod::MapWildList& Pokemod::MapWildList::operator=(const MapWildList& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(name); + COPY_SUB(MapWildListEncounter, encounters); + return *this; +} + +void Pokemod::MapWildList::clear() +{ + while (encounterCount()) + deleteEncounter(0); +} diff --git a/sigmod/MapWildList.h b/sigmod/MapWildList.h new file mode 100644 index 00000000..35027fa7 --- /dev/null +++ b/sigmod/MapWildList.h @@ -0,0 +1,77 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MAPWILDLIST__ +#define __POKEMOD_MAPWILDLIST__ + +// Pokemod includes +#include "Object.h" + +// Qt includes +#include <QtCore/QList> + +namespace Pokemod +{ +// Forward declarations +class Map; +class MapWildListEncounter; + +class POKEMOD_EXPORT MapWildList : public Object +{ + Q_OBJECT + + public: + MapWildList(const MapWildList& wildList); + MapWildList(const Map* parent, const int id); + MapWildList(const MapWildList& wildList, const Map* parent, const int id); + MapWildList(const QDomElement& xml, const Map* parent, const int id = -1); + ~MapWildList(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + + QString name() const; + + const MapWildListEncounter* encounter(const int index) const; + MapWildListEncounter* encounter(const int index); + const MapWildListEncounter* encounterById(const int id) const; + MapWildListEncounter* encounterById(const int id); + int encounterIndex(const int id) const; + int encounterCount() const; + MapWildListEncounter* newEncounter(); + MapWildListEncounter* newEncounter(const QDomElement& xml); + MapWildListEncounter* newEncounter(const MapWildListEncounter& encounter); + void deleteEncounter(const int index); + void deleteEncounterById(const int id); + + MapWildList& operator=(const MapWildList& rhs); + private: + int newEncounterId() const; + MapWildListEncounter* newEncounter(MapWildListEncounter* encounter); + + void clear(); + + QString m_name; + QList<MapWildListEncounter*> m_encounters; +}; +} + +#endif diff --git a/sigmod/MapWildListEncounter.cpp b/sigmod/MapWildListEncounter.cpp new file mode 100644 index 00000000..4ff41f4a --- /dev/null +++ b/sigmod/MapWildListEncounter.cpp @@ -0,0 +1,128 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "MapWildListEncounter.h" + +// Pokemod includes +#include "Macros.h" +#include "MapWildList.h" +#include "Pokemod.h" +#include "Rules.h" +#include "Species.h" + +Pokemod::MapWildListEncounter::MapWildListEncounter(const MapWildListEncounter& encounter) : + Object(encounter.parent(), encounter.id()) +{ + *this = encounter; +} + +Pokemod::MapWildListEncounter::MapWildListEncounter(const MapWildList* parent, const int id) : + Object(parent, id), + m_species(INT_MAX), + m_level(1), + m_weight(1) +{ +} + +Pokemod::MapWildListEncounter::MapWildListEncounter(const MapWildListEncounter& encounter, const MapWildList* parent, const int id) : + Object(parent, id) +{ + *this = encounter; +} + +Pokemod::MapWildListEncounter::MapWildListEncounter(const QDomElement& xml, const MapWildList* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::MapWildListEncounter::validate() +{ + TEST_BEGIN(); + TEST(setSpecies, species); + TEST(setLevel, level); + TEST(setWeight, weight); + TEST_END(); +} + +void Pokemod::MapWildListEncounter::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(species); + LOAD(level); + LOAD(weight); +} + +QDomElement Pokemod::MapWildListEncounter::save() const +{ + SAVE_CREATE(); + SAVE(species); + SAVE(level); + SAVE(weight); + return xml; +} + +void Pokemod::MapWildListEncounter::setSpecies(const int species) +{ + if (qobject_cast<const Pokemod*>(pokemod())->speciesIndex(species) == INT_MAX) + emit(error(bounds("species"))); + else + CHECK(species); +} + +void Pokemod::MapWildListEncounter::setLevel(const int level) +{ + if (!level || (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= level)) + emit(error(bounds("level"))); + else + CHECK(level); +} + +void Pokemod::MapWildListEncounter::setWeight(const int weight) +{ + if (!weight) + emit(error(bounds("weight"))); + else + CHECK(weight); +} + +int Pokemod::MapWildListEncounter::species() const +{ + return m_species; +} + +int Pokemod::MapWildListEncounter::level() const +{ + return m_level; +} + +int Pokemod::MapWildListEncounter::weight() const +{ + return m_weight; +} + +Pokemod::MapWildListEncounter& Pokemod::MapWildListEncounter::operator=(const MapWildListEncounter& rhs) +{ + if (this == &rhs) + return *this; + COPY(species); + COPY(level); + COPY(weight); + return *this; +} diff --git a/sigmod/MapWildListEncounter.h b/sigmod/MapWildListEncounter.h new file mode 100644 index 00000000..f6c942b8 --- /dev/null +++ b/sigmod/MapWildListEncounter.h @@ -0,0 +1,60 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MAPWILDLISTENCOUNTER__ +#define __POKEMOD_MAPWILDLISTENCOUNTER__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class MapWildList; + +class POKEMOD_EXPORT MapWildListEncounter: public Object +{ + Q_OBJECT + + public: + MapWildListEncounter(const MapWildListEncounter& encounter); + MapWildListEncounter(const MapWildList* parent, const int id); + MapWildListEncounter(const MapWildListEncounter& encounter, const MapWildList* parent, const int id); + MapWildListEncounter(const QDomElement& xml, const MapWildList* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setSpecies(const int species); + void setLevel(const int level); + void setWeight(const int weight); + + int species() const; + int level() const; + int weight() const; + + MapWildListEncounter& operator=(const MapWildListEncounter& rhs); + private: + int m_species; + int m_level; + int m_weight; +}; +} + +#endif diff --git a/sigmod/Matrix.h b/sigmod/Matrix.h new file mode 100644 index 00000000..8fe53fee --- /dev/null +++ b/sigmod/Matrix.h @@ -0,0 +1,248 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MATRIX__ +#define __POKEMOD_MATRIX__ + +// Pokemod includes +#include "Global.h" + +// Qt includes +#include <QtCore/QPoint> +#include <QtCore/QVector> + +namespace Pokemod +{ +template<class T> class POKEMOD_EXPORT Matrix +{ + public: + Matrix(); + Matrix(const int height, const int width, const T& value = T()); + Matrix(const Matrix<T>& rhs); + + void addRow(const T& value = T()); + void addColumn(const T& value = T()); + void insertRow(const int row, const T& value = T()); + void insertColumn(const int column, const T& value = T()); + void deleteRow(const int row); + void deleteColumn(const int column); + + void clear(); + + void set(const int row, const int column, const T& value); + void resize(const int newHeight, const int newWidth, const T& value = T()); + + T at(const int row, const int column) const; + QVector<T> row(const int row) const; + QVector<T> column(const int column) const; + + int height() const; + int width() const; + QPoint size() const; + + T& operator()(const int row, const int column); + T operator()(const int row, const int column) const; + Matrix<T>& operator=(const Matrix<T>& rhs); + bool operator==(const Matrix<T>& rhs) const; + bool operator!=(const Matrix<T>& rhs) const; + private: + QVector< QVector<T> > m_matrix; +}; + +template<class T> Matrix<T>::Matrix() +{ +} + +template<class T> Matrix<T>::Matrix(const int height, const int width, const T& value) +{ + resize(height, width, value); +} + +template<class T> Matrix<T>::Matrix(const Matrix<T>& rhs) +{ + *this = rhs; +} + +template<class T> void Matrix<T>::addRow(const T& value) +{ + if (size() == QPoint(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else + m_matrix.append(QVector<T>(width(), value)); +} + +template<class T> void Matrix<T>::addColumn(const T& value) +{ + if (size() == QPoint(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else + { + for (int i = 0; i < height(); ++i) + m_matrix[i].append(value); + } +} + +template<class T> void Matrix<T>::insertRow(const int row, const T& value) +{ + if (size() == QPoint(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else + { + Q_ASSERT(row <= height()); + m_matrix.insert(row, QVector<T>(width(), value)); + } +} + +template<class T> void Matrix<T>::insertColumn(const int column, const T& value) +{ + if (size() == QPoint(0, 0)) + m_matrix.append(QVector<T>(1, value)); + else + { + Q_ASSERT(column <= width()); + for (int i = 0; i < height(); ++i) + m_matrix[i].insert(column, value); + } +} + +template<class T> void Matrix<T>::deleteRow(const int row) +{ + if (height() == 1) + m_matrix.clear(); + else + { + Q_ASSERT(row < height()); + m_matrix.remove(row); + } +} + +template<class T> void Matrix<T>::deleteColumn(const int column) +{ + if (width() == 1) + m_matrix.clear(); + else + { + Q_ASSERT(column < width()); + for (int i = 0; i < height(); ++i) + m_matrix[i].remove(column); + } +} + +template<class T> void Matrix<T>::clear() +{ + m_matrix.clear(); +} + +template<class T> void Matrix<T>::set(const int row, const int column, const T& value) +{ + Q_ASSERT(row < height()); + Q_ASSERT(column < width()); + (m_matrix[row])[column] = value; +} + +template<class T> void Matrix<T>::resize(const int newHeight, const int newWidth, const T& value) +{ + while (height() < newHeight) + addRow(value); + while (newHeight < height()) + deleteRow(newHeight); + while (width() < newWidth) + addColumn(value); + while (newWidth < width()) + deleteColumn(newWidth); +} + +template<class T> T Matrix<T>::at(const int row, const int column) const +{ + Q_ASSERT(row < height()); + Q_ASSERT(column < width()); + return m_matrix.at(row).at(column); +} + +template<class T> QVector<T> Matrix<T>::row(const int row) const +{ + Q_ASSERT(row < height()); + return m_matrix.at(row); +} + +template<class T> QVector<T> Matrix<T>::column(const int column) const +{ + Q_ASSERT(column < width()); + QVector<T> col; + foreach (QVector<T> row, m_matrix) + col.append(row.at(column)); + return col; +} + +template<class T> int Matrix<T>::height() const +{ + return m_matrix.size(); +} + +template<class T> int Matrix<T>::width() const +{ + if (m_matrix.size()) + return m_matrix[0].size(); + return 0; +} + +template<class T> QPoint Matrix<T>::size() const +{ + return QPoint(height(), width()); +} + +template<class T> T& Matrix<T>::operator()(const int row, const int column) +{ + Q_ASSERT(row < height()); + Q_ASSERT(column < width()); + return m_matrix[row][column]; +} + +template<class T> T Matrix<T>::operator()(const int row, const int column) const +{ + return at(row, column); +} + +template<class T> Matrix<T>& Matrix<T>::operator=(const Matrix<T>& rhs) +{ + if (this == &rhs) + return *this; + resize(rhs.height(), rhs.width()); + for (int i = 0; i < height(); ++i) + { + for (int j = 0; j < width(); ++j) + m_matrix[i][j] = rhs.m_matrix[i][j]; + } + return *this; +} + +template<class T> bool Matrix<T>::operator==(const Matrix<T>& rhs) const +{ + if (this == &rhs) + return true; + return m_matrix == rhs.m_matrix; + return true; +} + +template<class T> bool Matrix<T>::operator!=(const Matrix<T>& rhs) const +{ + return !(*this == rhs); +} + +} + +#endif diff --git a/sigmod/Move.cpp b/sigmod/Move.cpp new file mode 100644 index 00000000..823739e5 --- /dev/null +++ b/sigmod/Move.cpp @@ -0,0 +1,233 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Move.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +// Qt includes +#include <QtCore/QSet> + +Pokemod::Move::Move(const Move& move) : + Object(move.parent(), move.id()) +{ + *this = move; +} + +Pokemod::Move::Move(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_accuracy(1, 1), + m_power(0), + m_type(INT_MAX), + m_special(false), + m_powerPoints(0), + m_priority(0), + m_description(""), + m_battleScript("", ""), + m_worldScript("", "") +{ +} + +Pokemod::Move::Move(const Move& move, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = move; +} + +Pokemod::Move::Move(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::Move::~Move() +{ + clear(); +} + +void Pokemod::Move::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setAccuracy, accuracy); + TEST(setType, type); + TEST(setPowerPoints, powerPoints); + TEST_END(); +} + +void Pokemod::Move::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(accuracy); + LOAD(power); + LOAD(type); + LOAD(special); + LOAD(powerPoints); + LOAD(priority); + LOAD(description); + LOAD(battleScript); + LOAD(worldScript); +} + +QDomElement Pokemod::Move::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(accuracy); + SAVE(power); + SAVE(type); + SAVE(special); + SAVE(powerPoints); + SAVE(priority); + SAVE(description); + SAVE(battleScript); + SAVE(worldScript); + return xml; +} + +void Pokemod::Move::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Move::setAccuracy(const Fraction& accuracy) +{ + if (!accuracy || (1 < accuracy)) + emit(error(bounds("accuracy"))); + else + CHECK(accuracy); +} + +void Pokemod::Move::setPower(const int power) +{ + CHECK(power); +} + +void Pokemod::Move::setType(const int type) +{ + if (qobject_cast<const Pokemod*>(pokemod())->typeIndex(type) == INT_MAX) + emit(error(bounds("type"))); + else + CHECK(type); +} + +void Pokemod::Move::setSpecial(const bool special) +{ + CHECK(special); +} + +void Pokemod::Move::setPowerPoints(const int powerPoints) +{ + if (!powerPoints) + emit(error(bounds("powerPoints"))); + else + CHECK(powerPoints); +} + +void Pokemod::Move::setPriority(const int priority) +{ + CHECK(priority); +} + +void Pokemod::Move::setDescription(const QString& description) +{ + CHECK(description); +} + +void Pokemod::Move::setBattleScript(const Script& battleScript) +{ + CHECK(battleScript); +} + +void Pokemod::Move::setWorldScript(const Script& worldScript) +{ + CHECK(worldScript); +} + +QString Pokemod::Move::name() const +{ + return m_name; +} + +Pokemod::Fraction Pokemod::Move::accuracy() const +{ + return m_accuracy; +} + +int Pokemod::Move::power() const +{ + return m_power; +} + +int Pokemod::Move::type() const +{ + return m_type; +} + +bool Pokemod::Move::special() const +{ + return m_special; +} + +int Pokemod::Move::powerPoints() const +{ + return m_powerPoints; +} + +int Pokemod::Move::priority() const +{ + return m_priority; +} + +QString Pokemod::Move::description() const +{ + return m_description; +} + +Pokemod::Script Pokemod::Move::battleScript() const +{ + return m_battleScript; +} + +Pokemod::Script Pokemod::Move::worldScript() const +{ + return m_worldScript; +} + +Pokemod::Move& Pokemod::Move::operator=(const Move& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(accuracy); + COPY(power); + COPY(type); + COPY(special); + COPY(powerPoints); + COPY(priority); + COPY(description); + COPY(battleScript); + COPY(worldScript); + return *this; +} diff --git a/sigmod/Move.h b/sigmod/Move.h new file mode 100644 index 00000000..0fe9efa2 --- /dev/null +++ b/sigmod/Move.h @@ -0,0 +1,84 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_MOVE__ +#define __POKEMOD_MOVE__ + +// Pokemod includes +#include "Fraction.h" +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Move : public Object +{ + Q_OBJECT + + public: + Move(const Move& move); + Move(const Pokemod* parent, const int id); + Move(const Move& move, const Pokemod* parent, const int id); + Move(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~Move(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setAccuracy(const Fraction& accuracy); + void setPower(const int power); + void setType(const int type); + void setSpecial(const bool special); + void setPowerPoints(const int powerPoints); + void setPriority(const int priority); + void setDescription(const QString& description); + void setBattleScript(const Script& battleScript); + void setWorldScript(const Script& worldScript); + + QString name() const; + Fraction accuracy() const; + int power() const; + int type() const; + bool special() const; + int powerPoints() const; + int priority() const; + QString description() const; + Script battleScript() const; + Script worldScript() const; + + Move& operator=(const Move& rhs); + private: + QString m_name; + Fraction m_accuracy; + int m_power; + int m_type; + bool m_special; + int m_powerPoints; + int m_priority; + QString m_description; + Script m_battleScript; + Script m_worldScript; +}; +} + +#endif diff --git a/sigmod/Nature.cpp b/sigmod/Nature.cpp new file mode 100644 index 00000000..e3018dea --- /dev/null +++ b/sigmod/Nature.cpp @@ -0,0 +1,144 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Nature.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Rules.h" + +Pokemod::Nature::Nature(const Nature& nature) : + Object(nature.parent(), nature.id()), + m_stat(ST_End_GSC - ST_No_HP_Start) +{ + *this = nature; +} + +Pokemod::Nature::Nature(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_stat(ST_End_GSC - ST_No_HP_Start), + m_weight(1) +{ + for (int i = 0; i < m_stat.size(); ++i) + m_stat[i].set(1, 1); +} + +Pokemod::Nature::Nature(const Nature& nature, const Pokemod* parent, const int id) : + Object(parent, id), + m_stat(ST_End_GSC - ST_No_HP_Start) +{ + *this = nature; +} + +Pokemod::Nature::Nature(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id), + m_stat(ST_End_GSC - ST_No_HP_Start) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Nature::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setWeight, weight); + TEST_END(); +} + +void Pokemod::Nature::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD_ARRAY(stat); + LOAD(weight); +} + +QDomElement Pokemod::Nature::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE_ARRAY(stat); + SAVE(weight); + return xml; +} + +void Pokemod::Nature::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Nature::setStat(const Stat stat, const Fraction& multiplier) +{ + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_Attack ... ST_Special: + break; + default: + emit(warning(bounds("stat"))); + return; + } + CHECK_ARRAY(stat[stat - ST_No_HP_Start], multiplier); +} + +void Pokemod::Nature::setWeight(const int weight) +{ + if (!weight) + emit(error(bounds("weight"))); + else + CHECK(weight); +} + +QString Pokemod::Nature::name() const +{ + return m_name; +} + +Pokemod::Fraction Pokemod::Nature::stat(const Stat stat) const +{ + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_Attack ... ST_Special: + return m_stat[stat - ST_No_HP_Start]; + default: + emit(warning(bounds("stat"))); + return Fraction(); + } +} + +int Pokemod::Nature::weight() const +{ + return m_weight; +} + +Pokemod::Nature& Pokemod::Nature::operator=(const Nature& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(stat); + COPY(weight); + return *this; +} diff --git a/sigmod/Nature.h b/sigmod/Nature.h new file mode 100644 index 00000000..bb9931ca --- /dev/null +++ b/sigmod/Nature.h @@ -0,0 +1,63 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_NATURE__ +#define __POKEMOD_NATURE__ + +// Pokemod includes +#include "Fraction.h" +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Nature : public Object +{ + Q_OBJECT + + public: + Nature(const Nature& nature); + Nature(const Pokemod* parent, const int id); + Nature(const Nature& nature, const Pokemod* parent, const int id); + Nature(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setStat(const Stat stat, const Fraction& multiplier); + void setWeight(const int weight); + + QString name() const; + Fraction stat(const Stat stat) const; + int weight() const; + + Nature& operator=(const Nature& rhs); + private: + void setStat(const Fraction& multiplier); + + QString m_name; + QVarLengthArray<Fraction, ST_End_GSC - ST_No_HP_Start> m_stat; + int m_weight; +}; +} + +#endif diff --git a/sigmod/Object.cpp b/sigmod/Object.cpp new file mode 100644 index 00000000..ce2425d8 --- /dev/null +++ b/sigmod/Object.cpp @@ -0,0 +1,94 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Object.h" + +// Pokemod includes +#include "Macros.h" + +Pokemod::Object::Object(const Object& object) : + QObject(NULL), + m_id(object.id()), + m_parent(object.parent()) +{ +} + +Pokemod::Object::Object(const Object* parent, const int id) : + QObject(NULL), + m_id(id), + m_parent(parent) +{ +} + +const Pokemod::Object* Pokemod::Object::parent() const +{ + return m_parent; +} + +const Pokemod::Object* Pokemod::Object::pokemod() const +{ + if (m_parent) + return m_parent->pokemod(); + return this; +} + +int Pokemod::Object::id() const +{ + return m_id; +} + +void Pokemod::Object::setId(const int id) +{ + CHECK(id); +} + +QString Pokemod::Object::className() const +{ + return QString(metaObject()->className()).section(':', -1); +} + +QDomDocument Pokemod::Object::xml(const Object* object) +{ + QDomDocument xml(object->className()); + xml.appendChild(object->save()); + return xml; +} + +QString Pokemod::Object::unused(const QString& variable) +{ + return QString("Setting unused variable %1").arg(variable); +} + +QString Pokemod::Object::bounds(const QString& variable) +{ + return QString("Value for %1 out-of-bounds").arg(variable); +} + +QString Pokemod::Object::subclass(const QString& subclass, const int id) +{ + return QString("Duplicate %1 with id %2").arg(subclass, id); +} + +QString Pokemod::Object::subclass(const QString& subclass, const QString& name) +{ + return QString("Duplicate %1 with name %2").arg(subclass, name); +} + +void Pokemod::Object::clear() +{ +} diff --git a/sigmod/Object.h b/sigmod/Object.h new file mode 100644 index 00000000..441b1e0d --- /dev/null +++ b/sigmod/Object.h @@ -0,0 +1,292 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_OBJECT__ +#define __POKEMOD_OBJECT__ + +// Pokemod includes +#include "Fraction.h" +#include "Global.h" +#include "Matrix.h" +#include "Script.h" + +// Qt includes +#include <QtCore/QBuffer> +#include <QtCore/QObject> +#include <QtCore/QPoint> +#include <QtCore/QVariant> +#include <QtCore/QVarLengthArray> +#include <QtGui/QImage> +#include <QtXml/QDomElement> + +// C includes +#include <climits> + +namespace Pokemod +{ +class POKEMOD_EXPORT Object : public QObject +{ + Q_OBJECT + + public: + Object(const Object& object); + Object(const Object* parent, const int id); + virtual ~Object(); + + const Object* parent() const; + const Object* pokemod() const; + + int id() const; + QString className() const; + + static QDomDocument xml(const Object* object); + + virtual void validate() = 0; + + virtual void load(const QDomElement& xml) = 0; + virtual QDomElement save() const = 0; + signals: + void valMessage(const QString& message) const; + void valWarning(const QString& message) const; + void valError(const QString& message) const; + void warning(const QString& message) const; + void error(const QString& message) const; + + void changed() const; + protected: + void setId(const int id); + + static QString unused(const QString& variable); + static QString bounds(const QString& variable); + static QString subclass(const QString& subclass, const int id); + static QString subclass(const QString& subclass, const QString& name); + + template<typename T> static void loadValue(const QDomElement& xml, T* value); + template<typename T, int S> static void loadArray(const QDomElement& xml, QVarLengthArray<T, S>* value); + template<typename T> static void loadList(const QDomElement& xml, QList<T>* value); + template<typename T> static void loadMatrix(const QDomElement& xml, Matrix<T>* value); + + template<typename T> static QDomElement saveValue(const QString& name, const T& value); + template<typename T, int S> static QDomElement saveArray(const QString& name, const QVarLengthArray<T, S>& value); + template<typename T> static QDomElement saveList(const QString& name, const QList<T>& value); + template<typename T> static QDomElement saveMatrix(const QString& name, const Matrix<T>& value); + + virtual void clear(); + private: + int m_id; + const Object* m_parent; +}; + +inline Object::~Object() +{ +} + +template<typename T> inline void Object::loadValue(const QDomElement& xml, T* value) +{ + *value = QVariant(xml.firstChild().toText().data()).value<T>(); +} + +template<> inline void Object::loadValue<bool>(const QDomElement& xml, bool* value) +{ + *value = (xml.firstChild().toText().data() == "true"); +} + +template<> inline void Object::loadValue<int>(const QDomElement& xml, int* value) +{ + *value = xml.firstChild().toText().data().toInt(); +} + +template<> inline void Object::loadValue<Fraction>(const QDomElement& xml, Fraction* value) +{ + value->set(xml.attribute("numerator", "1").toInt(), xml.attribute("denominator", "1").toInt()); +} + +template<> inline void Object::loadValue<QPoint>(const QDomElement& xml, QPoint* value) +{ + value->setX(xml.attribute("x", "0").toInt()); + value->setY(xml.attribute("y", "0").toInt()); +} + +template<> inline void Object::loadValue<QImage>(const QDomElement& xml, QImage* value) +{ + *value = QImage::fromData(QByteArray::fromBase64(xml.firstChild().toText().data().toUtf8())); +} + +template<> inline void Object::loadValue<QByteArray>(const QDomElement& xml, QByteArray* value) +{ + *value = QByteArray::fromBase64(xml.firstChild().toText().data().toUtf8()); +} + +template<> inline void Object::loadValue<Script>(const QDomElement& xml, Script* value) +{ + value->setInterpreter(xml.attribute("interpreter", "")); + value->setScript(xml.firstChild().toText().data()); +} + +template<typename T, int S> inline void Object::loadArray(const QDomElement& xml, QVarLengthArray<T, S>* value) +{ + QDomElement node = xml.firstChildElement("element"); + while (!node.isNull()) + { + int index = node.attribute("index", "-1").toInt(); + if ((0 <= index) && (index < value->size())) + loadValue(node, value->data() + index); + node = node.nextSiblingElement("element"); + } +} + +template<typename T> inline void Object::loadList(const QDomElement& xml, QList<T>* value) +{ + QDomElement node = xml.firstChildElement("element"); + T element; + while (!node.isNull()) + { + loadValue(node, &element); + if (!value->contains(element)) + value->append(element); + node = node.nextSiblingElement("element"); + } +} + +template<typename T> inline void Object::loadMatrix(const QDomElement& xml, Matrix<T>* value) +{ + int height = xml.attribute("height", "1").toInt(); + int width = xml.attribute("width", "1").toInt(); + value->resize(width, height); + QDomElement node = xml.firstChildElement("element"); + while (!node.isNull()) + { + int row = node.attribute("row", "-1").toInt(); + int column = node.attribute("column", "-1").toInt(); + if ((0 <= row) && (row < height) && (0 <= column) && (column < width)) + loadValue(node, &value->operator()(row, column)); + node = node.nextSiblingElement("element"); + } +} + +template<typename T> inline QDomElement Object::saveValue(const QString& name, const T& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.appendChild(QDomDocument().createTextNode(QVariant::fromValue<T>(value).toString())); + return element; +} + +template<> inline QDomElement Object::saveValue<bool>(const QString& name, const bool& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.appendChild(QDomDocument().createTextNode(value ? "true" : "false")); + return element; +} + +template<> inline QDomElement Object::saveValue<int>(const QString& name, const int& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.appendChild(QDomDocument().createTextNode(QString::number(value))); + return element; +} + +template<> inline QDomElement Object::saveValue<QString>(const QString& name, const QString& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.appendChild(QDomDocument().createTextNode(value)); + return element; +} + +template<> inline QDomElement Object::saveValue<Fraction>(const QString& name, const Fraction& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.setAttribute("numerator", value.numerator()); + element.setAttribute("denominator", value.denominator()); + return element; +} + +template<> inline QDomElement Object::saveValue<QPoint>(const QString& name, const QPoint& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.setAttribute("x", value.x()); + element.setAttribute("y", value.y()); + return element; +} + +template<> inline QDomElement Object::saveValue<QImage>(const QString& name, const QImage& value) +{ + QDomElement element = QDomDocument().createElement(name); + QByteArray bytes; + QBuffer* buffer = new QBuffer(&bytes); + buffer->open(QIODevice::WriteOnly); + value.save(buffer, "PNG"); + element.appendChild(QDomDocument().createTextNode(bytes.toBase64())); + delete buffer; + return element; +} + +template<> inline QDomElement Object::saveValue<QByteArray>(const QString& name, const QByteArray& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.appendChild(QDomDocument().createTextNode(value.toBase64())); + return element; +} + +template<> inline QDomElement Object::saveValue<Script>(const QString& name, const Script& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.setAttribute("interpreter", value.interpreter()); + element.appendChild(QDomDocument().createCDATASection(value.script())); + return element; +} + +template<typename T, int S> inline QDomElement Object::saveArray(const QString& name, const QVarLengthArray<T, S>& value) +{ + QDomElement element = QDomDocument().createElement(name); + for (int i = 0; i < value.size(); ++i) + { + QDomElement valueElement = saveValue("element", value[i]); + valueElement.setAttribute("index", QString::number(i)); + element.appendChild(valueElement); + } + return element; +} + +template<typename T> inline QDomElement Object::saveList(const QString& name, const QList<T>& value) +{ + QDomElement element = QDomDocument().createElement(name); + for (int i = 0; i < value.size(); ++i) + element.appendChild(saveValue("element", value.at(i))); + return element; +} + +template<typename T> inline QDomElement Object::saveMatrix(const QString& name, const Matrix<T>& value) +{ + QDomElement element = QDomDocument().createElement(name); + element.setAttribute("height", value.height()); + element.setAttribute("width", value.width()); + for (int i = 0; i < value.height(); ++i) + { + for (int j = 0; j < value.width(); ++j) + { + QDomElement valueElement = saveValue("element", value(i, j)); + valueElement.setAttribute("row", QString::number(i)); + valueElement.setAttribute("column", QString::number(j)); + element.appendChild(valueElement); + } + } + return element; +} + +} + +#endif diff --git a/sigmod/Pokemod.cpp b/sigmod/Pokemod.cpp new file mode 100644 index 00000000..67355553 --- /dev/null +++ b/sigmod/Pokemod.cpp @@ -0,0 +1,2244 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Pokemod.h" + +// Pokemod includes +#include "Ability.h" +#include "Author.h" +#include "Badge.h" +#include "CoinList.h" +#include "EggGroup.h" +#include "GlobalScript.h" +#include "Item.h" +#include "ItemType.h" +#include "Macros.h" +#include "Map.h" +#include "Move.h" +#include "Nature.h" +#include "Rules.h" +#include "Skin.h" +#include "Sound.h" +#include "Species.h" +#include "Sprite.h" +#include "Status.h" +#include "Store.h" +#include "Tile.h" +#include "Time.h" +#include "Trainer.h" +#include "Type.h" +#include "Weather.h" + +// Qt includes +#include <QtCore/QSet> + +Pokemod::Pokemod::Pokemod() : + Object(NULL, 0), + m_title(""), + m_version(""), + m_description(""), + m_startMap(INT_MAX), + m_startWarp(INT_MAX), + m_typechart(0, 0), + m_rules(new Rules(this)) +{ +} + +Pokemod::Pokemod::Pokemod(const Pokemod& pokemod) : + Object(NULL, 0), + m_rules(new Rules(this)) +{ + *this = pokemod; +} + +Pokemod::Pokemod::Pokemod(const QDomElement& xml) : + Object(NULL, 0), + m_rules(new Rules(this)) +{ + load(xml); +} + +Pokemod::Pokemod::~Pokemod() +{ + delete m_rules; + clear(); +} + +void Pokemod::Pokemod::validate() +{ + TEST_BEGIN(); + if (m_title.isEmpty()) + emit(error("Title is empty")); + if (m_version.isEmpty()) + emit(error("Version is empty")); + if (m_description.isEmpty()) + emit(warning("Description is empty")); + if (mapIndex(m_startMap) == INT_MAX) + emit(error("Invalid starting map")); + else if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX) + emit(error("Invalid starting warp")); + if ((m_typechart.width() != typeCount()) || (m_typechart.height() != typeCount())) + emit(error("Type chart is invalid")); + TEST_CHILD(m_rules); + QSet<int> idChecker; + QSet<QString> nameChecker; + QSet<int> timeChecker; + if (abilityCount() < m_rules->maxAbilities()) + emit(error("There are too few abilities")); + TEST_SUB_BEGIN(Ability, abilities); + TEST_SUB("ability", id); + TEST_SUB("ability", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!authorCount()) + emit(error("There are no authors")); + TEST_SUB_BEGIN(Author, authors); + TEST_SUB("author", id); + TEST_SUB("author", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!badgeCount()) + emit(error("There are no badges")); + TEST_SUB_BEGIN(Badge, badges); + TEST_SUB("badge", id); + TEST_SUB("badge", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!coinListCount()) + emit(warning("There are no coin lists")); + TEST_SUB_BEGIN(CoinList, coinLists); + TEST_SUB("coin list", id); + TEST_SUB("coin list", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (m_rules->breedingAllowed()) + { + if (!eggGroupCount()) + emit(error("There are no egg groups")); + TEST_SUB_BEGIN(EggGroup, eggGroups); + TEST_SUB("egg group", id); + TEST_SUB("egg group", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + } + if (!globalScriptCount()) + emit(warning("There are no global scripts")); + TEST_SUB_BEGIN(GlobalScript, globalScripts); + TEST_SUB("global script", id); + TEST_SUB("global script", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!itemCount()) + emit(warning("There are no items")); + TEST_SUB_BEGIN(Item, items); + TEST_SUB("item", id); + TEST_SUB("item", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!itemTypeCount() && itemCount()) + emit(error("There are no item types")); + TEST_SUB_BEGIN(ItemType, itemTypes); + TEST_SUB("item type", id); + TEST_SUB("item type", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!mapCount()) + emit(error("There are no maps")); + TEST_SUB_BEGIN(Map, maps); + TEST_SUB("map", id); + TEST_SUB("map", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!moveCount()) + emit(error("There are no moves")); + TEST_SUB_BEGIN(Move, moves); + TEST_SUB("move", id); + TEST_SUB("move", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (natureCount() < m_rules->maxNatures()) + emit(error("There are too few natures")); + TEST_SUB_BEGIN(Nature, natures); + TEST_SUB("nature", id); + TEST_SUB("nature", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + TEST_SUB_BEGIN(Skin, skins); + TEST_SUB("skin", id); + TEST_SUB("skin", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!soundCount()) + emit(warning("There are no sounds")); + TEST_SUB_BEGIN(Sound, sounds); + TEST_SUB("sound", id); + TEST_SUB("sound", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!speciesCount()) + emit(error("There are no species")); + TEST_SUB_BEGIN(Species, species); + TEST_SUB("species", id); + TEST_SUB("species", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!statusCount()) + emit(error("There are no status effects")); + TEST_SUB_BEGIN(Status, status); + TEST_SUB("status", id); + TEST_SUB("status", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!storeCount()) + emit(warning("There are no stores")); + TEST_SUB_BEGIN(Store, stores); + TEST_SUB("store", id); + TEST_SUB("store", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!tileCount()) + emit(error("There are no tiles")); + TEST_SUB_BEGIN(Tile, tiles); + TEST_SUB("tile", id); + TEST_SUB("tile", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!trainerCount()) + emit(warning("There are no trainers")); + TEST_SUB_BEGIN(Trainer, trainers); + TEST_SUB("trainer", id); + TEST_SUB("trainer", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!timeCount()) + emit(error("There are no times")); + TEST_SUB_BEGIN(Time, times); + TEST_SUB("time", id); + TEST_SUB("time", name); + if (timeChecker.contains((60 * object->hour()) + object->minute())) + emit(error(subclass("time", QString("%1:%2").arg(object->hour(), object->minute())))); + timeChecker.insert((60 * object->hour()) + object->minute()); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!typeCount()) + emit(error("There are no types")); + TEST_SUB_BEGIN(Type, types); + TEST_SUB("type", id); + TEST_SUB("type", name); + TEST_SUB_END(); + idChecker.clear(); + nameChecker.clear(); + if (!weatherCount()) + emit(warning("There are no weathers")); + TEST_SUB_BEGIN(Weather, weathers); + TEST_SUB("weather", id); + TEST_SUB("weather", name); + TEST_SUB_END(); + TEST_END(); +} + +void Pokemod::Pokemod::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(title); + LOAD(version); + LOAD(description); + LOAD(startMap); + LOAD(startWarp); + LOAD_Rules(); + LOAD_SUB(newAbility, Ability); + LOAD_SUB(newAuthor, Author); + LOAD_SUB(newBadge, Badge); + LOAD_SUB(newCoinList, CoinList); + LOAD_SUB(newEggGroup, EggGroup); + LOAD_SUB(newGlobalScript, GlobalScript); + LOAD_SUB(newItem, Item); + LOAD_SUB(newItemType, ItemType); + LOAD_SUB(newMap, Map); + LOAD_SUB(newMove, Move); + LOAD_SUB(newNature, Nature); + LOAD_SUB(newSkin, Skin); + LOAD_SUB(newSound, Sound); + LOAD_SUB(newSpecies, Species); + LOAD_SUB(newSprite, Sprite); + LOAD_SUB(newStatus, Status); + LOAD_SUB(newStore, Store); + LOAD_SUB(newTile, Tile); + LOAD_SUB(newTime, Time); + LOAD_SUB(newTrainer, Trainer); + LOAD_SUB(newType, Type); + LOAD_SUB(newWeather, Weather); + LOAD_MATRIX(typechart); + m_typechart.resize(typeCount(), typeCount()); +} + +QDomElement Pokemod::Pokemod::save() const +{ + QDomElement xml = QDomDocument().createElement(className()); + SAVE(title); + SAVE(version); + SAVE(description); + SAVE(startMap); + SAVE(startWarp); + SAVE_Rules(rules); + SAVE_MATRIX(typechart); + SAVE_SUB(Ability, abilities); + SAVE_SUB(Author, authors); + SAVE_SUB(Badge, badges); + SAVE_SUB(CoinList, coinLists); + SAVE_SUB(EggGroup, eggGroups); + SAVE_SUB(GlobalScript, globalScripts); + SAVE_SUB(Item, items); + SAVE_SUB(ItemType, itemTypes); + SAVE_SUB(Map, maps); + SAVE_SUB(Move, moves); + SAVE_SUB(Nature, natures); + SAVE_SUB(Skin, skins); + SAVE_SUB(Sound, sounds); + SAVE_SUB(Species, species); + SAVE_SUB(Sprite, sprites); + SAVE_SUB(Status, status); + SAVE_SUB(Store, stores); + SAVE_SUB(Tile, tiles); + SAVE_SUB(Time, times); + SAVE_SUB(Trainer, trainers); + SAVE_SUB(Type, types); + SAVE_SUB(Weather, weathers); + return xml; +} + +void Pokemod::Pokemod::setTitle(const QString& title) +{ + CHECK(title); +} + +void Pokemod::Pokemod::setVersion(const QString& version) +{ + CHECK(version); +} + +void Pokemod::Pokemod::setDescription(const QString& description) +{ + CHECK(description); +} + +void Pokemod::Pokemod::setStartMap(const int startMap) +{ + if (mapIndex(startMap) == INT_MAX) + emit(error(bounds("startMap"))); + else + CHECK(startMap); +} + +void Pokemod::Pokemod::setStartWarp(const int startWarp) +{ + if (mapIndex(m_startMap) == INT_MAX) + emit(error(bounds("startMap"))); + else if (mapById(m_startMap)->warpIndex(startWarp) == INT_MAX) + emit(error(bounds("startWarp"))); + else + CHECK(startWarp); +} + +void Pokemod::Pokemod::setTypechart(const int attack, const int defense, const Fraction& multiplier) +{ + CHECK_ARRAY(typechart(attack, defense), multiplier); +} + +void Pokemod::Pokemod::setRules(const Rules& rules) +{ + *m_rules = rules; +} + +void Pokemod::Pokemod::setRules(const QDomElement& xml) +{ + m_rules->load(xml); +} + +QString Pokemod::Pokemod::title() const +{ + return m_title; +} + +QString Pokemod::Pokemod::version() const +{ + return m_version; +} + +QString Pokemod::Pokemod::description() const +{ + return m_description; +} + +int Pokemod::Pokemod::startMap() const +{ + return m_startMap; +} + +int Pokemod::Pokemod::startWarp() const +{ + return m_startWarp; +} + +const Pokemod::Matrix<Pokemod::Fraction>* Pokemod::Pokemod::typechart() const +{ + return &m_typechart; +} + +Pokemod::Matrix<Pokemod::Fraction>* Pokemod::Pokemod::typechart() +{ + return &m_typechart; +} + +Pokemod::Fraction Pokemod::Pokemod::typechart(const int attack, const int defense) const +{ + return m_typechart(attack, defense); +} + +const Pokemod::Rules* Pokemod::Pokemod::rules() const +{ + return m_rules; +} + +Pokemod::Rules* Pokemod::Pokemod::rules() +{ + return m_rules; +} + +const Pokemod::Ability* Pokemod::Pokemod::ability(const int index) const +{ + Q_ASSERT(index < abilityCount()); + return m_abilities.at(index); +} + +Pokemod::Ability* Pokemod::Pokemod::ability(const int index) +{ + Q_ASSERT(index < abilityCount()); + return m_abilities[index]; +} + +const Pokemod::Ability* Pokemod::Pokemod::abilityById(const int id) const +{ + return ability(abilityIndex(id)); +} + +Pokemod::Ability* Pokemod::Pokemod::abilityById(const int id) +{ + return ability(abilityIndex(id)); +} + +int Pokemod::Pokemod::abilityIndex(const int id) const +{ + for (int i = 0; i < abilityCount(); ++i) + { + if (m_abilities[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::abilityCount() const +{ + return m_abilities.size(); +} + +Pokemod::Ability* Pokemod::Pokemod::newAbility() +{ + return newAbility(new Ability(this, newAbilityId())); +} + +Pokemod::Ability* Pokemod::Pokemod::newAbility(const QDomElement& xml) +{ + return newAbility(new Ability(xml, this, newAbilityId())); +} + +Pokemod::Ability* Pokemod::Pokemod::newAbility(const Ability& ability) +{ + return newAbility(new Ability(ability, this, newAbilityId())); +} + +Pokemod::Ability* Pokemod::Pokemod::newAbility(Ability* ability) +{ + m_abilities.append(ability); + return ability; +} + +void Pokemod::Pokemod::deleteAbility(const int index) +{ + Q_ASSERT(index < abilityCount()); + delete m_abilities[index]; + m_abilities.removeAt(index); +} + +void Pokemod::Pokemod::deleteAbilityById(const int id) +{ + deleteAbility(abilityIndex(id)); +} + +int Pokemod::Pokemod::newAbilityId() const +{ + int i = 0; + while ((i < abilityCount()) && (abilityIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Author* Pokemod::Pokemod::author(const int index) const +{ + Q_ASSERT(index < authorCount()); + return m_authors.at(index); +} + +Pokemod::Author* Pokemod::Pokemod::author(const int index) +{ + Q_ASSERT(index < authorCount()); + return m_authors[index]; +} + +const Pokemod::Author* Pokemod::Pokemod::authorById(const int id) const +{ + return author(authorIndex(id)); +} + +Pokemod::Author* Pokemod::Pokemod::authorById(const int id) +{ + return author(authorIndex(id)); +} + +int Pokemod::Pokemod::authorIndex(const int id) const +{ + for (int i = 0; i < authorCount(); ++i) + { + if (m_authors[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::authorCount() const +{ + return m_authors.size(); +} + +Pokemod::Author* Pokemod::Pokemod::newAuthor() +{ + return newAuthor(new Author(this, newAuthorId())); +} + +Pokemod::Author* Pokemod::Pokemod::newAuthor(const QDomElement& xml) +{ + return newAuthor(new Author(xml, this, newAuthorId())); +} + +Pokemod::Author* Pokemod::Pokemod::newAuthor(const Author& author) +{ + return newAuthor(new Author(author, this, newAuthorId())); +} + +Pokemod::Author* Pokemod::Pokemod::newAuthor(Author* author) +{ + m_authors.append(author); + return author; +} + +void Pokemod::Pokemod::deleteAuthor(const int index) +{ + Q_ASSERT(index < authorCount()); + delete m_authors[index]; + m_authors.removeAt(index); +} + +void Pokemod::Pokemod::deleteAuthorById(const int id) +{ + deleteAuthor(authorIndex(id)); +} + +int Pokemod::Pokemod::newAuthorId() const +{ + int i = 0; + while ((i < authorCount()) && (authorIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Badge* Pokemod::Pokemod::badge(const int index) const +{ + Q_ASSERT(index < badgeCount()); + return m_badges.at(index); +} + +Pokemod::Badge* Pokemod::Pokemod::badge(const int index) +{ + Q_ASSERT(index < badgeCount()); + return m_badges[index]; +} + +const Pokemod::Badge* Pokemod::Pokemod::badgeById(const int id) const +{ + return badge(badgeIndex(id)); +} + +Pokemod::Badge* Pokemod::Pokemod::badgeById(const int id) +{ + return badge(badgeIndex(id)); +} + +int Pokemod::Pokemod::badgeIndex(const int id) const +{ + for (int i = 0; i < badgeCount(); ++i) + { + if (m_badges[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::badgeCount() const +{ + return m_badges.size(); +} + +Pokemod::Badge* Pokemod::Pokemod::newBadge() +{ + return newBadge(new Badge(this, newBadgeId())); +} + +Pokemod::Badge* Pokemod::Pokemod::newBadge(const QDomElement& xml) +{ + return newBadge(new Badge(xml, this, newBadgeId())); +} + +Pokemod::Badge* Pokemod::Pokemod::newBadge(const Badge& badge) +{ + return newBadge(new Badge(badge, this, newBadgeId())); +} + +Pokemod::Badge* Pokemod::Pokemod::newBadge(Badge* badge) +{ + m_badges.append(badge); + return badge; +} + +void Pokemod::Pokemod::deleteBadge(const int index) +{ + Q_ASSERT(index < badgeCount()); + delete m_badges[index]; + m_badges.removeAt(index); +} + +void Pokemod::Pokemod::deleteBadgeById(const int id) +{ + deleteBadge(badgeIndex(id)); +} + +int Pokemod::Pokemod::newBadgeId() const +{ + int i = 0; + while ((i < badgeCount()) && (badgeIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::CoinList* Pokemod::Pokemod::coinList(const int index) const +{ + Q_ASSERT(index < coinListCount()); + return m_coinLists.at(index); +} + +Pokemod::CoinList* Pokemod::Pokemod::coinList(const int index) +{ + Q_ASSERT(index < coinListCount()); + return m_coinLists[index]; +} + +const Pokemod::CoinList* Pokemod::Pokemod::coinListById(const int id) const +{ + return coinList(coinListIndex(id)); +} + +Pokemod::CoinList* Pokemod::Pokemod::coinListById(const int id) +{ + return coinList(coinListIndex(id)); +} + +int Pokemod::Pokemod::coinListIndex(const int id) const +{ + for (int i = 0; i < coinListCount(); ++i) + { + if (m_coinLists[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::coinListCount() const +{ + return m_coinLists.size(); +} + +Pokemod::CoinList* Pokemod::Pokemod::newCoinList() +{ + return newCoinList(new CoinList(this, newCoinListId())); +} + +Pokemod::CoinList* Pokemod::Pokemod::newCoinList(const QDomElement& xml) +{ + return newCoinList(new CoinList(xml, this, newCoinListId())); +} + +Pokemod::CoinList* Pokemod::Pokemod::newCoinList(const CoinList& coinList) +{ + return newCoinList(new CoinList(coinList, this, newCoinListId())); +} + +Pokemod::CoinList* Pokemod::Pokemod::newCoinList(CoinList* coinList) +{ + m_coinLists.append(coinList); + return coinList; +} + +void Pokemod::Pokemod::deleteCoinList(const int index) +{ + Q_ASSERT(index < coinListCount()); + delete m_coinLists[index]; + m_coinLists.removeAt(index); +} + +void Pokemod::Pokemod::deleteCoinListById(const int id) +{ + deleteCoinList(coinListIndex(id)); +} + +int Pokemod::Pokemod::newCoinListId() const +{ + int i = 0; + while ((i < coinListCount()) && (coinListIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::EggGroup* Pokemod::Pokemod::eggGroup(const int index) const +{ + Q_ASSERT(index < eggGroupCount()); + return m_eggGroups.at(index); +} + +Pokemod::EggGroup* Pokemod::Pokemod::eggGroup(const int index) +{ + Q_ASSERT(index < eggGroupCount()); + return m_eggGroups[index]; +} + +const Pokemod::EggGroup* Pokemod::Pokemod::eggGroupById(const int id) const +{ + return eggGroup(eggGroupIndex(id)); +} + +Pokemod::EggGroup* Pokemod::Pokemod::eggGroupById(const int id) +{ + return eggGroup(eggGroupIndex(id)); +} + +int Pokemod::Pokemod::eggGroupIndex(const int id) const +{ + for (int i = 0; i < eggGroupCount(); ++i) + { + if (m_eggGroups[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::eggGroupCount() const +{ + return m_eggGroups.size(); +} + +Pokemod::EggGroup* Pokemod::Pokemod::newEggGroup() +{ + return newEggGroup(new EggGroup(this, newEggGroupId())); +} + +Pokemod::EggGroup* Pokemod::Pokemod::newEggGroup(const QDomElement& xml) +{ + return newEggGroup(new EggGroup(xml, this, newEggGroupId())); +} + +Pokemod::EggGroup* Pokemod::Pokemod::newEggGroup(const EggGroup& eggGroup) +{ + return newEggGroup(new EggGroup(eggGroup, this, newEggGroupId())); +} + +Pokemod::EggGroup* Pokemod::Pokemod::newEggGroup(EggGroup* eggGroup) +{ + m_eggGroups.append(eggGroup); + return eggGroup; +} + +void Pokemod::Pokemod::deleteEggGroup(const int index) +{ + Q_ASSERT(index < eggGroupCount()); + delete m_eggGroups[index]; + m_eggGroups.removeAt(index); +} + +void Pokemod::Pokemod::deleteEggGroupById(const int id) +{ + deleteEggGroup(eggGroupIndex(id)); +} + +int Pokemod::Pokemod::newEggGroupId() const +{ + int i = 0; + while ((i < eggGroupCount()) && (eggGroupIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::GlobalScript* Pokemod::Pokemod::globalScript(const int index) const +{ + Q_ASSERT(index < globalScriptCount()); + return m_globalScripts.at(index); +} + +Pokemod::GlobalScript* Pokemod::Pokemod::globalScript(const int index) +{ + Q_ASSERT(index < globalScriptCount()); + return m_globalScripts[index]; +} + +const Pokemod::GlobalScript* Pokemod::Pokemod::globalScriptById(const int id) const +{ + return globalScript(globalScriptIndex(id)); +} + +Pokemod::GlobalScript* Pokemod::Pokemod::globalScriptById(const int id) +{ + return globalScript(globalScriptIndex(id)); +} + +int Pokemod::Pokemod::globalScriptIndex(const int id) const +{ + for (int i = 0; i < globalScriptCount(); ++i) + { + if (m_globalScripts[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::globalScriptCount() const +{ + return m_globalScripts.size(); +} + +Pokemod::GlobalScript* Pokemod::Pokemod::newGlobalScript() +{ + return newGlobalScript(new GlobalScript(this, newGlobalScriptId())); +} + +Pokemod::GlobalScript* Pokemod::Pokemod::newGlobalScript(const QDomElement& xml) +{ + return newGlobalScript(new GlobalScript(xml, this, newGlobalScriptId())); +} + +Pokemod::GlobalScript* Pokemod::Pokemod::newGlobalScript(const GlobalScript& globalScript) +{ + return newGlobalScript(new GlobalScript(globalScript, this, newGlobalScriptId())); +} + +Pokemod::GlobalScript* Pokemod::Pokemod::newGlobalScript(GlobalScript* globalScript) +{ + m_globalScripts.append(globalScript); + return globalScript; +} + +void Pokemod::Pokemod::deleteGlobalScript(const int index) +{ + Q_ASSERT(index < globalScriptCount()); + delete m_globalScripts[index]; + m_globalScripts.removeAt(index); +} + +void Pokemod::Pokemod::deleteGlobalScriptById(const int id) +{ + deleteGlobalScript(globalScriptIndex(id)); +} + +int Pokemod::Pokemod::newGlobalScriptId() const +{ + int i = 0; + while ((i < globalScriptCount()) && (globalScriptIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Item* Pokemod::Pokemod::item(const int index) const +{ + Q_ASSERT(index < itemCount()); + return m_items.at(index); +} + +Pokemod::Item* Pokemod::Pokemod::item(const int index) +{ + Q_ASSERT(index < itemCount()); + return m_items[index]; +} + +const Pokemod::Item* Pokemod::Pokemod::itemById(const int id) const +{ + return item(itemIndex(id)); +} + +Pokemod::Item* Pokemod::Pokemod::itemById(const int id) +{ + return item(itemIndex(id)); +} + +int Pokemod::Pokemod::itemIndex(const int id) const +{ + for (int i = 0; i < itemCount(); ++i) + { + if (m_items[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::itemCount() const +{ + return m_items.size(); +} + +Pokemod::Item* Pokemod::Pokemod::newItem() +{ + return newItem(new Item(this, newItemId())); +} + +Pokemod::Item* Pokemod::Pokemod::newItem(const QDomElement& xml) +{ + return newItem(new Item(xml, this, newItemId())); +} + +Pokemod::Item* Pokemod::Pokemod::newItem(const Item& item) +{ + return newItem(new Item(item, this, newItemId())); +} + +Pokemod::Item* Pokemod::Pokemod::newItem(Item* item) +{ + m_items.append(item); + return item; +} + +void Pokemod::Pokemod::deleteItem(const int index) +{ + Q_ASSERT(index < itemCount()); + delete m_items[index]; + m_items.removeAt(index); +} + +void Pokemod::Pokemod::deleteItemById(const int id) +{ + deleteItem(itemIndex(id)); +} + +int Pokemod::Pokemod::newItemId() const +{ + int i = 0; + for (; (i < itemCount()) && (itemIndex(i) != INT_MAX); ++i) + ; + return i; +} + +const Pokemod::ItemType* Pokemod::Pokemod::itemType(const int index) const +{ + Q_ASSERT(index < itemTypeCount()); + return m_itemTypes.at(index); +} + +Pokemod::ItemType* Pokemod::Pokemod::itemType(const int index) +{ + Q_ASSERT(index < itemTypeCount()); + return m_itemTypes[index]; +} + +const Pokemod::ItemType* Pokemod::Pokemod::itemTypeById(const int id) const +{ + return itemType(itemTypeIndex(id)); +} + +Pokemod::ItemType* Pokemod::Pokemod::itemTypeById(const int id) +{ + return itemType(itemTypeIndex(id)); +} + +int Pokemod::Pokemod::itemTypeIndex(const int id) const +{ + for (int i = 0; i < itemTypeCount(); ++i) + { + if (m_itemTypes[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::itemTypeCount() const +{ + return m_itemTypes.size(); +} + +Pokemod::ItemType* Pokemod::Pokemod::newItemType() +{ + return newItemType(new ItemType(this, newItemTypeId())); +} + +Pokemod::ItemType* Pokemod::Pokemod::newItemType(const QDomElement& xml) +{ + return newItemType(new ItemType(xml, this, newItemTypeId())); +} + +Pokemod::ItemType* Pokemod::Pokemod::newItemType(const ItemType& itemType) +{ + return newItemType(new ItemType(itemType, this, newItemTypeId())); +} + +Pokemod::ItemType* Pokemod::Pokemod::newItemType(ItemType* itemType) +{ + m_itemTypes.append(itemType); + return itemType; +} + +void Pokemod::Pokemod::deleteItemType(const int index) +{ + Q_ASSERT(index < itemTypeCount()); + delete m_itemTypes[index]; + m_itemTypes.removeAt(index); +} + +void Pokemod::Pokemod::deleteItemTypeById(const int id) +{ + deleteItemType(itemTypeIndex(id)); +} + +int Pokemod::Pokemod::newItemTypeId() const +{ + int i = 0; + while ((i < itemTypeCount()) && (itemTypeIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Map* Pokemod::Pokemod::map(const int index) const +{ + Q_ASSERT(index < mapCount()); + return m_maps.at(index); +} + +Pokemod::Map* Pokemod::Pokemod::map(const int index) +{ + Q_ASSERT(index < mapCount()); + return m_maps[index]; +} + +const Pokemod::Map* Pokemod::Pokemod::mapById(const int id) const +{ + return map(mapIndex(id)); +} + +Pokemod::Map* Pokemod::Pokemod::mapById(const int id) +{ + return map(mapIndex(id)); +} + +int Pokemod::Pokemod::mapIndex(const int id) const +{ + for (int i = 0; i < mapCount(); ++i) + { + if (m_maps[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::mapCount() const +{ + return m_maps.size(); +} + +Pokemod::Map* Pokemod::Pokemod::newMap() +{ + return newMap(new Map(this, newMapId())); +} + +Pokemod::Map* Pokemod::Pokemod::newMap(const QDomElement& xml) +{ + return newMap(new Map(xml, this, newMapId())); +} + +Pokemod::Map* Pokemod::Pokemod::newMap(const Map& map) +{ + return newMap(new Map(map, this, newMapId())); +} + +Pokemod::Map* Pokemod::Pokemod::newMap(Map* map) +{ + m_maps.append(map); + return map; +} + +void Pokemod::Pokemod::deleteMap(const int index) +{ + Q_ASSERT(index < mapCount()); + delete m_maps[index]; + m_maps.removeAt(index); +} + +void Pokemod::Pokemod::deleteMapById(const int id) +{ + deleteMap(mapIndex(id)); +} + +int Pokemod::Pokemod::newMapId() const +{ + int i = 0; + while ((i < mapCount()) && (mapIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Move* Pokemod::Pokemod::move(const int index) const +{ + Q_ASSERT(index < moveCount()); + return m_moves.at(index); +} + +Pokemod::Move* Pokemod::Pokemod::move(const int index) +{ + Q_ASSERT(index < moveCount()); + return m_moves[index]; +} + +const Pokemod::Move* Pokemod::Pokemod::moveById(const int id) const +{ + return move(moveIndex(id)); +} + +Pokemod::Move* Pokemod::Pokemod::moveById(const int id) +{ + return move(moveIndex(id)); +} + +int Pokemod::Pokemod::moveIndex(const int id) const +{ + for (int i = 0; i < moveCount(); ++i) + { + if (m_moves[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::moveCount() const +{ + return m_moves.size(); +} + +Pokemod::Move* Pokemod::Pokemod::newMove() +{ + return newMove(new Move(this, newMoveId())); +} + +Pokemod::Move* Pokemod::Pokemod::newMove(const QDomElement& xml) +{ + return newMove(new Move(xml, this, newMoveId())); +} + +Pokemod::Move* Pokemod::Pokemod::newMove(const Move& move) +{ + return newMove(new Move(move, this, newMoveId())); +} + +Pokemod::Move* Pokemod::Pokemod::newMove(Move* move) +{ + m_moves.append(move); + return move; +} + +void Pokemod::Pokemod::deleteMove(const int index) +{ + Q_ASSERT(index < moveCount()); + delete m_moves[index]; + m_moves.removeAt(index); +} + +void Pokemod::Pokemod::deleteMoveById(const int id) +{ + deleteMove(moveIndex(id)); +} + +int Pokemod::Pokemod::newMoveId() const +{ + int i = 0; + while ((i < moveCount()) && (moveIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Nature* Pokemod::Pokemod::nature(const int index) const +{ + Q_ASSERT(index < natureCount()); + return m_natures.at(index); +} + +Pokemod::Nature* Pokemod::Pokemod::nature(const int index) +{ + Q_ASSERT(index < natureCount()); + return m_natures[index]; +} + +const Pokemod::Nature* Pokemod::Pokemod::natureById(const int id) const +{ + return nature(natureIndex(id)); +} + +Pokemod::Nature* Pokemod::Pokemod::natureById(const int id) +{ + return nature(natureIndex(id)); +} + +int Pokemod::Pokemod::natureIndex(const int id) const +{ + for (int i = 0; i < natureCount(); ++i) + { + if (m_natures[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::natureCount() const +{ + return m_natures.size(); +} + +Pokemod::Nature* Pokemod::Pokemod::newNature() +{ + return newNature(new Nature(this, newNatureId())); +} + +Pokemod::Nature* Pokemod::Pokemod::newNature(const QDomElement& xml) +{ + return newNature(new Nature(xml, this, newNatureId())); +} + +Pokemod::Nature* Pokemod::Pokemod::newNature(const Nature& nature) +{ + return newNature(new Nature(nature, this, newNatureId())); +} + +Pokemod::Nature* Pokemod::Pokemod::newNature(Nature* nature) +{ + m_natures.append(nature); + return nature; +} + +void Pokemod::Pokemod::deleteNature(const int index) +{ + Q_ASSERT(index < natureCount()); + delete m_natures[index]; + m_natures.removeAt(index); +} + +void Pokemod::Pokemod::deleteNatureById(const int id) +{ + deleteNature(natureIndex(id)); +} + +int Pokemod::Pokemod::newNatureId() const +{ + int i = 0; + while ((i < natureCount()) && (natureIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Skin* Pokemod::Pokemod::skin(const int index) const +{ + Q_ASSERT(index < skinCount()); + return m_skins.at(index); +} + +Pokemod::Skin* Pokemod::Pokemod::skin(const int index) +{ + Q_ASSERT(index < skinCount()); + return m_skins[index]; +} + +const Pokemod::Skin* Pokemod::Pokemod::skinById(const int id) const +{ + return skin(skinIndex(id)); +} + +Pokemod::Skin* Pokemod::Pokemod::skinById(const int id) +{ + return skin(skinIndex(id)); +} + +int Pokemod::Pokemod::skinIndex(const int id) const +{ + for (int i = 0; i < skinCount(); ++i) + { + if (m_skins[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::skinCount() const +{ + return m_skins.size(); +} + +Pokemod::Skin* Pokemod::Pokemod::newSkin() +{ + return newSkin(new Skin(this, newSkinId())); +} + +Pokemod::Skin* Pokemod::Pokemod::newSkin(const QDomElement& xml) +{ + return newSkin(new Skin(xml, this, newSkinId())); +} + +Pokemod::Skin* Pokemod::Pokemod::newSkin(const Skin& skin) +{ + return newSkin(new Skin(skin, this, newSkinId())); +} + +Pokemod::Skin* Pokemod::Pokemod::newSkin(Skin* skin) +{ + m_skins.append(skin); + return skin; +} + +void Pokemod::Pokemod::deleteSkin(const int index) +{ + Q_ASSERT(index < skinCount()); + delete m_skins[index]; + m_skins.removeAt(index); +} + +void Pokemod::Pokemod::deleteSkinById(const int id) +{ + deleteSkin(skinIndex(id)); +} + +int Pokemod::Pokemod::newSkinId() const +{ + int i = 0; + while ((i < skinCount()) && (skinIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Sound* Pokemod::Pokemod::sound(const int index) const +{ + Q_ASSERT(index < soundCount()); + return m_sounds.at(index); +} + +Pokemod::Sound* Pokemod::Pokemod::sound(const int index) +{ + Q_ASSERT(index < soundCount()); + return m_sounds[index]; +} + +const Pokemod::Sound* Pokemod::Pokemod::soundById(const int id) const +{ + return sound(soundIndex(id)); +} + +Pokemod::Sound* Pokemod::Pokemod::soundById(const int id) +{ + return sound(soundIndex(id)); +} + +int Pokemod::Pokemod::soundIndex(const int id) const +{ + for (int i = 0; i < soundCount(); ++i) + { + if (m_sounds[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::soundCount() const +{ + return m_sounds.size(); +} + +Pokemod::Sound* Pokemod::Pokemod::newSound() +{ + return newSound(new Sound(this, newSoundId())); +} + +Pokemod::Sound* Pokemod::Pokemod::newSound(const QDomElement& xml) +{ + return newSound(new Sound(xml, this, newSoundId())); +} + +Pokemod::Sound* Pokemod::Pokemod::newSound(const Sound& sound) +{ + return newSound(new Sound(sound, this, newSoundId())); +} + +Pokemod::Sound* Pokemod::Pokemod::newSound(Sound* sound) +{ + m_sounds.append(sound); + return sound; +} + +void Pokemod::Pokemod::deleteSound(const int index) +{ + Q_ASSERT(index < soundCount()); + delete m_sounds[index]; + m_sounds.removeAt(index); +} + +void Pokemod::Pokemod::deleteSoundById(const int id) +{ + deleteSound(soundIndex(id)); +} + +int Pokemod::Pokemod::newSoundId() const +{ + int i = 0; + while ((i < soundCount()) && (soundIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Species* Pokemod::Pokemod::species(const int index) const +{ + Q_ASSERT(index < speciesCount()); + return m_species.at(index); +} + +Pokemod::Species* Pokemod::Pokemod::species(const int index) +{ + Q_ASSERT(index < speciesCount()); + return m_species[index]; +} + +const Pokemod::Species* Pokemod::Pokemod::speciesById(const int id) const +{ + return species(speciesIndex(id)); +} + +Pokemod::Species* Pokemod::Pokemod::speciesById(const int id) +{ + return species(speciesIndex(id)); +} + +int Pokemod::Pokemod::speciesIndex(const int id) const +{ + for (int i = 0; i < speciesCount(); ++i) + { + if (m_species[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::speciesCount() const +{ + return m_species.size(); +} + +Pokemod::Species* Pokemod::Pokemod::newSpecies() +{ + return newSpecies(new Species(this, newSpeciesId())); +} + +Pokemod::Species* Pokemod::Pokemod::newSpecies(const QDomElement& xml) +{ + return newSpecies(new Species(xml, this, newSpeciesId())); +} + +Pokemod::Species* Pokemod::Pokemod::newSpecies(const Species& species) +{ + return newSpecies(new Species(species, this, newSpeciesId())); +} + +Pokemod::Species* Pokemod::Pokemod::newSpecies(Species* species) +{ + m_species.append(species); + return species; +} + +void Pokemod::Pokemod::deleteSpecies(const int index) +{ + Q_ASSERT(index < speciesCount()); + delete m_species[index]; + m_species.removeAt(index); +} + +void Pokemod::Pokemod::deleteSpeciesById(const int id) +{ + deleteSpecies(speciesIndex(id)); +} + +int Pokemod::Pokemod::newSpeciesId() const +{ + int i = 0; + while ((i < speciesCount()) && (speciesIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Sprite* Pokemod::Pokemod::sprite(const int index) const +{ + Q_ASSERT(index < spriteCount()); + return m_sprites.at(index); +} + +Pokemod::Sprite* Pokemod::Pokemod::sprite(const int index) +{ + Q_ASSERT(index < spriteCount()); + return m_sprites[index]; +} + +const Pokemod::Sprite* Pokemod::Pokemod::spriteById(const int id) const +{ + return sprite(spriteIndex(id)); +} + +Pokemod::Sprite* Pokemod::Pokemod::spriteById(const int id) +{ + return sprite(spriteIndex(id)); +} + +int Pokemod::Pokemod::spriteIndex(const int id) const +{ + for (int i = 0; i < spriteCount(); ++i) + { + if (m_sprites[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::spriteCount() const +{ + return m_sprites.size(); +} + +Pokemod::Sprite* Pokemod::Pokemod::newSprite() +{ + return newSprite(new Sprite(this, newSpriteId())); +} + +Pokemod::Sprite* Pokemod::Pokemod::newSprite(const QDomElement& xml) +{ + return newSprite(new Sprite(xml, this, newSpriteId())); +} + +Pokemod::Sprite* Pokemod::Pokemod::newSprite(const Sprite& sprite) +{ + return newSprite(new Sprite(sprite, this, newSpriteId())); +} + +Pokemod::Sprite* Pokemod::Pokemod::newSprite(Sprite* sprite) +{ + m_sprites.append(sprite); + return sprite; +} + +void Pokemod::Pokemod::deleteSprite(const int index) +{ + Q_ASSERT(index < spriteCount()); + delete m_sprites[index]; + m_sprites.removeAt(index); +} + +void Pokemod::Pokemod::deleteSpriteById(const int id) +{ + deleteSprite(spriteIndex(id)); +} + +int Pokemod::Pokemod::newSpriteId() const +{ + int i = 0; + while ((i < spriteCount()) && (spriteIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Status* Pokemod::Pokemod::status(const int index) const +{ + Q_ASSERT(index < statusCount()); + return m_status.at(index); +} + +Pokemod::Status* Pokemod::Pokemod::status(const int index) +{ + Q_ASSERT(index < statusCount()); + return m_status[index]; +} + +const Pokemod::Status* Pokemod::Pokemod::statusById(const int id) const +{ + return status(statusIndex(id)); +} + +Pokemod::Status* Pokemod::Pokemod::statusById(const int id) +{ + return status(statusIndex(id)); +} + +int Pokemod::Pokemod::statusIndex(const int id) const +{ + for (int i = 0; i < statusCount(); ++i) + { + if (m_status[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::statusCount() const +{ + return m_status.size(); +} + +Pokemod::Status* Pokemod::Pokemod::newStatus() +{ + return newStatus(new Status(this, newStatusId())); +} + +Pokemod::Status* Pokemod::Pokemod::newStatus(const QDomElement& xml) +{ + return newStatus(new Status(xml, this, newStatusId())); +} + +Pokemod::Status* Pokemod::Pokemod::newStatus(const Status& status) +{ + return newStatus(new Status(status, this, newStatusId())); +} + +Pokemod::Status* Pokemod::Pokemod::newStatus(Status* status) +{ + m_status.append(status); + return status; +} + +void Pokemod::Pokemod::deleteStatus(const int index) +{ + Q_ASSERT(index < statusCount()); + delete m_status[index]; + m_status.removeAt(index); +} + +void Pokemod::Pokemod::deleteStatusById(const int id) +{ + deleteStatus(statusIndex(id)); +} + +int Pokemod::Pokemod::newStatusId() const +{ + int i = 0; + while ((i < statusCount()) && (statusIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Store* Pokemod::Pokemod::store(const int index) const +{ + Q_ASSERT(index < storeCount()); + return m_stores.at(index); +} + +Pokemod::Store* Pokemod::Pokemod::store(const int index) +{ + Q_ASSERT(index < storeCount()); + return m_stores[index]; +} + +const Pokemod::Store* Pokemod::Pokemod::storeById(const int id) const +{ + return store(storeIndex(id)); +} + +Pokemod::Store* Pokemod::Pokemod::storeById(const int id) +{ + return store(storeIndex(id)); +} + +int Pokemod::Pokemod::storeIndex(const int id) const +{ + for (int i = 0; i < storeCount(); ++i) + { + if (m_stores[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::storeCount() const +{ + return m_stores.size(); +} + +Pokemod::Store* Pokemod::Pokemod::newStore() +{ + return newStore(new Store(this, newStoreId())); +} + +Pokemod::Store* Pokemod::Pokemod::newStore(const QDomElement& xml) +{ + return newStore(new Store(xml, this, newStoreId())); +} + +Pokemod::Store* Pokemod::Pokemod::newStore(const Store& store) +{ + return newStore(new Store(store, this, newStoreId())); +} + +Pokemod::Store* Pokemod::Pokemod::newStore(Store* store) +{ + m_stores.append(store); + return store; +} + +void Pokemod::Pokemod::deleteStore(const int index) +{ + Q_ASSERT(index < storeCount()); + delete m_stores[index]; + m_stores.removeAt(index); +} + +void Pokemod::Pokemod::deleteStoreById(const int id) +{ + deleteStore(storeIndex(id)); +} + +int Pokemod::Pokemod::newStoreId() const +{ + int i = 0; + while ((i < storeCount()) && (storeIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Tile* Pokemod::Pokemod::tile(const int index) const +{ + Q_ASSERT(index < tileCount()); + return m_tiles.at(index); +} + +Pokemod::Tile* Pokemod::Pokemod::tile(const int index) +{ + Q_ASSERT(index < tileCount()); + return m_tiles[index]; +} + +const Pokemod::Tile* Pokemod::Pokemod::tileById(const int id) const +{ + return tile(tileIndex(id)); +} + +Pokemod::Tile* Pokemod::Pokemod::tileById(const int id) +{ + return tile(tileIndex(id)); +} + +int Pokemod::Pokemod::tileIndex(const int id) const +{ + for (int i = 0; i < tileCount(); ++i) + { + if (m_tiles[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::tileCount() const +{ + return m_tiles.size(); +} + +Pokemod::Tile* Pokemod::Pokemod::newTile() +{ + return newTile(new Tile(this, newTileId())); +} + +Pokemod::Tile* Pokemod::Pokemod::newTile(const QDomElement& xml) +{ + return newTile(new Tile(xml, this, newTileId())); +} + +Pokemod::Tile* Pokemod::Pokemod::newTile(const Tile& tile) +{ + return newTile(new Tile(tile, this, newTileId())); +} + +Pokemod::Tile* Pokemod::Pokemod::newTile(Tile* tile) +{ + m_tiles.append(tile); + return tile; +} + +void Pokemod::Pokemod::deleteTile(const int index) +{ + Q_ASSERT(index < tileCount()); + delete m_tiles[index]; + m_tiles.removeAt(index); +} + +void Pokemod::Pokemod::deleteTileById(const int id) +{ + deleteTile(tileIndex(id)); +} + +int Pokemod::Pokemod::newTileId() const +{ + int i = 0; + while ((i < tileCount()) && (tileIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Time* Pokemod::Pokemod::time(const int index) const +{ + Q_ASSERT(index < timeCount()); + return m_times.at(index); +} + +Pokemod::Time* Pokemod::Pokemod::time(const int index) +{ + Q_ASSERT(index < timeCount()); + return m_times[index]; +} + +const Pokemod::Time* Pokemod::Pokemod::timeById(const int id) const +{ + return time(timeIndex(id)); +} + +Pokemod::Time* Pokemod::Pokemod::timeById(const int id) +{ + return time(timeIndex(id)); +} + +int Pokemod::Pokemod::timeIndex(const int id) const +{ + for (int i = 0; i < timeCount(); ++i) + { + if (m_times[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::timeCount() const +{ + return m_times.size(); +} + +Pokemod::Time* Pokemod::Pokemod::newTime() +{ + return newTime(new Time(this, newTimeId())); +} + +Pokemod::Time* Pokemod::Pokemod::newTime(const QDomElement& xml) +{ + return newTime(new Time(xml, this, newTimeId())); +} + +Pokemod::Time* Pokemod::Pokemod::newTime(const Time& time) +{ + return newTime(new Time(time, this, newTimeId())); +} + +Pokemod::Time* Pokemod::Pokemod::newTime(Time* time) +{ + m_times.append(time); + return time; +} + +void Pokemod::Pokemod::deleteTime(const int index) +{ + Q_ASSERT(index < timeCount()); + delete m_times[index]; + m_times.removeAt(index); +} + +void Pokemod::Pokemod::deleteTimeById(const int id) +{ + deleteTime(timeIndex(id)); +} + +int Pokemod::Pokemod::newTimeId() const +{ + int i = 0; + while ((i < timeCount()) && (timeIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Trainer* Pokemod::Pokemod::trainer(const int index) const +{ + Q_ASSERT(index < trainerCount()); + return m_trainers.at(index); +} + +Pokemod::Trainer* Pokemod::Pokemod::trainer(const int index) +{ + Q_ASSERT(index < trainerCount()); + return m_trainers[index]; +} + +const Pokemod::Trainer* Pokemod::Pokemod::trainerById(const int id) const +{ + return trainer(trainerIndex(id)); +} + +Pokemod::Trainer* Pokemod::Pokemod::trainerById(const int id) +{ + return trainer(trainerIndex(id)); +} + +int Pokemod::Pokemod::trainerIndex(const int id) const +{ + for (int i = 0; i < trainerCount(); ++i) + { + if (m_trainers[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::trainerCount() const +{ + return m_trainers.size(); +} + +Pokemod::Trainer* Pokemod::Pokemod::newTrainer() +{ + return newTrainer(new Trainer(this, newTrainerId())); +} + +Pokemod::Trainer* Pokemod::Pokemod::newTrainer(const QDomElement& xml) +{ + return newTrainer(new Trainer(xml, this, newTrainerId())); +} + +Pokemod::Trainer* Pokemod::Pokemod::newTrainer(const Trainer& trainer) +{ + return newTrainer(new Trainer(trainer, this, newTrainerId())); +} + +Pokemod::Trainer* Pokemod::Pokemod::newTrainer(Trainer* trainer) +{ + m_trainers.append(trainer); + return trainer; +} + +void Pokemod::Pokemod::deleteTrainer(const int index) +{ + Q_ASSERT(index < trainerCount()); + delete m_trainers[index]; + m_trainers.removeAt(index); +} + +void Pokemod::Pokemod::deleteTrainerById(const int id) +{ + deleteTrainer(trainerIndex(id)); +} + +int Pokemod::Pokemod::newTrainerId() const +{ + int i = 0; + while ((i < trainerCount()) && (trainerIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Type* Pokemod::Pokemod::type(const int index) const +{ + Q_ASSERT(index < typeCount()); + return m_types.at(index); +} + +Pokemod::Type* Pokemod::Pokemod::type(const int index) +{ + Q_ASSERT(index < typeCount()); + return m_types[index]; +} + +const Pokemod::Type* Pokemod::Pokemod::typeById(const int id) const +{ + return type(typeIndex(id)); +} + +Pokemod::Type* Pokemod::Pokemod::typeById(const int id) +{ + return type(typeIndex(id)); +} + +int Pokemod::Pokemod::typeIndex(const int id) const +{ + for (int i = 0; i < typeCount(); ++i) + { + if (m_types[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::typeCount() const +{ + return m_types.size(); +} + +Pokemod::Type* Pokemod::Pokemod::newType() +{ + return newType(new Type(this, newTypeId())); +} + +Pokemod::Type* Pokemod::Pokemod::newType(const QDomElement& xml) +{ + return newType(new Type(xml, this, newTypeId())); +} + +Pokemod::Type* Pokemod::Pokemod::newType(const Type& type) +{ + return newType(new Type(type, this, newTypeId())); +} + +Pokemod::Type* Pokemod::Pokemod::newType(Type* type) +{ + m_types.append(type); + m_typechart.resize(typeCount(), typeCount(), Fraction(1, 1)); + return type; +} + +void Pokemod::Pokemod::deleteType(const int index) +{ + Q_ASSERT(index < typeCount()); + delete m_types[index]; + m_types.removeAt(index); + m_typechart.resize(typeCount(), typeCount(), Fraction(1, 1)); +} + +void Pokemod::Pokemod::deleteTypeById(const int id) +{ + deleteType(typeIndex(id)); +} + +int Pokemod::Pokemod::newTypeId() const +{ + int i = 0; + while ((i < typeCount()) && (typeIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::Weather* Pokemod::Pokemod::weather(const int index) const +{ + Q_ASSERT(index < weatherCount()); + return m_weathers.at(index); +} + +Pokemod::Weather* Pokemod::Pokemod::weather(const int index) +{ + Q_ASSERT(index < weatherCount()); + return m_weathers[index]; +} + +const Pokemod::Weather* Pokemod::Pokemod::weatherById(const int id) const +{ + return weather(weatherIndex(id)); +} + +Pokemod::Weather* Pokemod::Pokemod::weatherById(const int id) +{ + return weather(weatherIndex(id)); +} + +int Pokemod::Pokemod::weatherIndex(const int id) const +{ + for (int i = 0; i < weatherCount(); ++i) + { + if (m_weathers[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Pokemod::weatherCount() const +{ + return m_weathers.size(); +} + +Pokemod::Weather* Pokemod::Pokemod::newWeather() +{ + return newWeather(new Weather(this, newWeatherId())); +} + +Pokemod::Weather* Pokemod::Pokemod::newWeather(const QDomElement& xml) +{ + return newWeather(new Weather(xml, this, newWeatherId())); +} + +Pokemod::Weather* Pokemod::Pokemod::newWeather(const Weather& weather) +{ + return newWeather(new Weather(weather, this, newWeatherId())); +} + +Pokemod::Weather* Pokemod::Pokemod::newWeather(Weather* weather) +{ + m_weathers.append(weather); + return weather; +} + +void Pokemod::Pokemod::deleteWeather(const int index) +{ + Q_ASSERT(index < weatherCount()); + delete m_weathers[index]; + m_weathers.removeAt(index); +} + +void Pokemod::Pokemod::deleteWeatherById(const int id) +{ + deleteWeather(weatherIndex(id)); +} + +int Pokemod::Pokemod::newWeatherId() const +{ + int i = 0; + while ((i < weatherCount()) && (weatherIndex(i) != INT_MAX)) + ++i; + return i; +} + +Pokemod::Pokemod& Pokemod::Pokemod::operator=(const Pokemod& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(title); + COPY(version); + COPY(description); + COPY(startMap); + COPY(startWarp); + COPY(typechart); + COPY_Rules(rules); + COPY_SUB(Ability, abilities); + COPY_SUB(Author, authors); + COPY_SUB(Badge, badges); + COPY_SUB(CoinList, coinLists); + COPY_SUB(EggGroup, eggGroups); + COPY_SUB(GlobalScript, globalScripts); + COPY_SUB(Item, items); + COPY_SUB(ItemType, itemTypes); + COPY_SUB(Map, maps); + COPY_SUB(Move, moves); + COPY_SUB(Nature, natures); + COPY_SUB(Skin, skins); + COPY_SUB(Sound, sounds); + COPY_SUB(Species, species); + COPY_SUB(Sprite, sprites); + COPY_SUB(Status, status); + COPY_SUB(Store, stores); + COPY_SUB(Tile, tiles); + COPY_SUB(Time, times); + COPY_SUB(Trainer, trainers); + COPY_SUB(Type, types); + COPY_SUB(Weather, weathers); + m_typechart.resize(typeCount(), typeCount()); + return *this; +} + +void Pokemod::Pokemod::clear() +{ + while (abilityCount()) + deleteAbility(0); + while (authorCount()) + deleteAuthor(0); + while (badgeCount()) + deleteBadge(0); + while (coinListCount()) + deleteCoinList(0); + while (eggGroupCount()) + deleteEggGroup(0); + while (globalScriptCount()) + deleteGlobalScript(0); + while (itemCount()) + deleteItem(0); + while (itemTypeCount()) + deleteItemType(0); + while (mapCount()) + deleteMap(0); + while (moveCount()) + deleteMove(0); + while (natureCount()) + deleteNature(0); + while (skinCount()) + deleteSkin(0); + while (soundCount()) + deleteSound(0); + while (speciesCount()) + deleteSpecies(0); + while (spriteCount()) + deleteSprite(0); + while (statusCount()) + deleteStatus(0); + while (storeCount()) + deleteStore(0); + while (tileCount()) + deleteTile(0); + while (timeCount()) + deleteTime(0); + while (trainerCount()) + deleteTrainer(0); + while (typeCount()) + deleteType(0); + while (weatherCount()) + deleteWeather(0); +} diff --git a/sigmod/Pokemod.h b/sigmod/Pokemod.h new file mode 100644 index 00000000..d5539d21 --- /dev/null +++ b/sigmod/Pokemod.h @@ -0,0 +1,457 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_POKEMOD__ +#define __POKEMOD_POKEMOD__ + +// Pokemod includes +#include "Fraction.h" +#include "Matrix.h" +#include "Object.h" + +// Qt includes +#include <QtCore/QList> + +namespace Pokemod +{ +// Forward declarations +class Ability; +class Author; +class Badge; +class CoinList; +class EggGroup; +class GlobalScript; +class Item; +class ItemType; +class Map; +class Move; +class Nature; +class Rules; +class Skin; +class Sound; +class Species; +class Sprite; +class Status; +class Store; +class Tile; +class Time; +class Trainer; +class Type; +class Weather; + +class POKEMOD_EXPORT Pokemod : public Object +{ + Q_OBJECT + + public: + Pokemod(); + Pokemod(const Pokemod& pokemod); + Pokemod(const QDomElement& xml); + ~Pokemod(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setTitle(const QString& title); + void setVersion(const QString& version); + void setDescription(const QString& description); + void setStartMap(const int startMap); + void setStartWarp(const int startWarp); + void setTypechart(const int attack, const int defense, const Fraction& multiplier); + void setRules(const Rules& rules); + void setRules(const QDomElement& xml); + + QString title() const; + QString version() const; + QString description() const; + int startMap() const; + int startWarp() const; + const Matrix<Fraction>* typechart() const; + Matrix<Fraction>* typechart(); + Fraction typechart(const int attack, const int defense) const; + const Rules* rules() const; + Rules* rules(); + + const Ability* ability(const int index) const; + Ability* ability(const int index); + const Ability* abilityById(const int id) const; + Ability* abilityById(const int id); + int abilityIndex(const int id) const; + int abilityCount() const; + Ability* newAbility(); + Ability* newAbility(const QDomElement& xml); + Ability* newAbility(const Ability& ability); + void deleteAbility(const int index); + void deleteAbilityById(const int id); + + const Author* author(const int index) const; + Author* author(const int index); + const Author* authorById(const int id) const; + Author* authorById(const int id); + int authorIndex(const int id) const; + int authorCount() const; + Author* newAuthor(); + Author* newAuthor(const QDomElement& xml); + Author* newAuthor(const Author& author); + void deleteAuthor(const int index); + void deleteAuthorById(const int id); + + const Badge* badge(const int index) const; + Badge* badge(const int index); + const Badge* badgeById(const int id) const; + Badge* badgeById(const int id); + int badgeIndex(const int id) const; + int badgeCount() const; + Badge* newBadge(); + Badge* newBadge(const QDomElement& xml); + Badge* newBadge(const Badge& badge); + void deleteBadge(const int index); + void deleteBadgeById(const int id); + + const CoinList* coinList(const int index) const; + CoinList* coinList(const int index); + const CoinList* coinListById(const int id) const; + CoinList* coinListById(const int id); + int coinListIndex(const int id) const; + int coinListCount() const; + CoinList* newCoinList(); + CoinList* newCoinList(const QDomElement& xml); + CoinList* newCoinList(const CoinList& coinList); + void deleteCoinList(const int index); + void deleteCoinListById(const int id); + + const EggGroup* eggGroup(const int index) const; + EggGroup* eggGroup(const int index); + const EggGroup* eggGroupById(const int id) const; + EggGroup* eggGroupById(const int id); + int eggGroupIndex(const int id) const; + int eggGroupCount() const; + EggGroup* newEggGroup(); + EggGroup* newEggGroup(const QDomElement& xml); + EggGroup* newEggGroup(const EggGroup& eggGroup); + void deleteEggGroup(const int index); + void deleteEggGroupById(const int id); + + const GlobalScript* globalScript(const int index) const; + GlobalScript* globalScript(const int index); + const GlobalScript* globalScriptById(const int id) const; + GlobalScript* globalScriptById(const int id); + int globalScriptIndex(const int id) const; + int globalScriptCount() const; + GlobalScript* newGlobalScript(); + GlobalScript* newGlobalScript(const QDomElement& xml); + GlobalScript* newGlobalScript(const GlobalScript& globalScript); + void deleteGlobalScript(const int index); + void deleteGlobalScriptById(const int id); + + const Item* item(const int index) const; + Item* item(const int index); + const Item* itemById(const int id) const; + Item* itemById(const int id); + int itemIndex(const int id) const; + int itemCount() const; + Item* newItem(); + Item* newItem(const QDomElement& xml); + Item* newItem(const Item& item); + void deleteItem(const int index); + void deleteItemById(const int id); + + const ItemType* itemType(const int index) const; + ItemType* itemType(const int index); + const ItemType* itemTypeById(const int id) const; + ItemType* itemTypeById(const int id); + int itemTypeIndex(const int id) const; + int itemTypeCount() const; + ItemType* newItemType(); + ItemType* newItemType(const QDomElement& xml); + ItemType* newItemType(const ItemType& itemType); + void deleteItemType(const int index); + void deleteItemTypeById(const int id); + + const Map* map(const int index) const; + Map* map(const int index); + const Map* mapById(const int id) const; + Map* mapById(const int id); + int mapIndex(const int id) const; + int mapCount() const; + Map* newMap(); + Map* newMap(const QDomElement& xml); + Map* newMap(const Map& map); + void deleteMap(const int index); + void deleteMapById(const int id); + + const Move* move(const int index) const; + Move* move(const int index); + const Move* moveById(const int id) const; + Move* moveById(const int id); + int moveIndex(const int id) const; + int moveCount() const; + Move* newMove(); + Move* newMove(const QDomElement& xml); + Move* newMove(const Move& move); + void deleteMove(const int index); + void deleteMoveById(const int id); + + const Nature* nature(const int index) const; + Nature* nature(const int index); + const Nature* natureById(const int id) const; + Nature* natureById(const int id); + int natureIndex(const int id) const; + int natureCount() const; + Nature* newNature(); + Nature* newNature(const QDomElement& xml); + Nature* newNature(const Nature& nature); + void deleteNature(const int index); + void deleteNatureById(const int id); + + const Skin* skin(const int index) const; + Skin* skin(const int index); + const Skin* skinById(const int id) const; + Skin* skinById(const int id); + int skinIndex(const int id) const; + int skinCount() const; + Skin* newSkin(); + Skin* newSkin(const QDomElement& xml); + Skin* newSkin(const Skin& status); + void deleteSkin(const int index); + void deleteSkinById(const int id); + + const Sound* sound(const int index) const; + Sound* sound(const int index); + const Sound* soundById(const int id) const; + Sound* soundById(const int id); + int soundIndex(const int id) const; + int soundCount() const; + Sound* newSound(); + Sound* newSound(const QDomElement& xml); + Sound* newSound(const Sound& sound); + void deleteSound(const int index); + void deleteSoundById(const int id); + + const Species* species(const int index) const; + Species* species(const int index); + const Species* speciesById(const int id) const; + Species* speciesById(const int id); + int speciesIndex(const int id) const; + int speciesCount() const; + Species* newSpecies(); + Species* newSpecies(const QDomElement& xml); + Species* newSpecies(const Species& species); + void deleteSpecies(const int index); + void deleteSpeciesById(const int id); + + const Sprite* sprite(const int index) const; + Sprite* sprite(const int index); + const Sprite* spriteById(const int id) const; + Sprite* spriteById(const int id); + int spriteIndex(const int id) const; + int spriteCount() const; + Sprite* newSprite(); + Sprite* newSprite(const QDomElement& xml); + Sprite* newSprite(const Sprite& sprite); + void deleteSprite(const int index); + void deleteSpriteById(const int id); + + const Status* status(const int index) const; + Status* status(const int index); + const Status* statusById(const int id) const; + Status* statusById(const int id); + int statusIndex(const int id) const; + int statusCount() const; + Status* newStatus(); + Status* newStatus(const QDomElement& xml); + Status* newStatus(const Status& status); + void deleteStatus(const int index); + void deleteStatusById(const int id); + + const Store* store(const int index) const; + Store* store(const int index); + const Store* storeById(const int id) const; + Store* storeById(const int id); + int storeIndex(const int id) const; + int storeCount() const; + Store* newStore(); + Store* newStore(const QDomElement& xml); + Store* newStore(const Store& store); + void deleteStore(const int index); + void deleteStoreById(const int id); + + const Tile* tile(const int index) const; + Tile* tile(const int index); + const Tile* tileById(const int id) const; + Tile* tileById(const int id); + int tileIndex(const int id) const; + int tileCount() const; + Tile* newTile(); + Tile* newTile(const QDomElement& xml); + Tile* newTile(const Tile& tile); + void deleteTile(const int index); + void deleteTileById(const int id); + + const Time* time(const int index) const; + Time* time(const int index); + const Time* timeById(const int id) const; + Time* timeById(const int id); + int timeIndex(const int id) const; + int timeCount() const; + Time* newTime(); + Time* newTime(const QDomElement& xml); + Time* newTime(const Time& time); + void deleteTime(const int index); + void deleteTimeById(const int id); + + const Trainer* trainer(const int index) const; + Trainer* trainer(const int index); + const Trainer* trainerById(const int id) const; + Trainer* trainerById(const int id); + int trainerIndex(const int id) const; + int trainerCount() const; + Trainer* newTrainer(); + Trainer* newTrainer(const QDomElement& xml); + Trainer* newTrainer(const Trainer& trainer); + void deleteTrainer(const int index); + void deleteTrainerById(const int id); + + const Type* type(const int index) const; + Type* type(const int index); + const Type* typeById(const int id) const; + Type* typeById(const int id); + int typeIndex(const int id) const; + int typeCount() const; + Type* newType(); + Type* newType(const QDomElement& xml); + Type* newType(const Type& type); + void deleteType(const int index); + void deleteTypeById(const int id); + + const Weather* weather(const int index) const; + Weather* weather(const int index); + const Weather* weatherById(const int id) const; + Weather* weatherById(const int id); + int weatherIndex(const int id) const; + int weatherCount() const; + Weather* newWeather(); + Weather* newWeather(const QDomElement& xml); + Weather* newWeather(const Weather& weather); + void deleteWeather(const int index); + void deleteWeatherById(const int id); + + Pokemod& operator=(const Pokemod& rhs); + private: + void validate(); + + int newAbilityId() const; + Ability* newAbility(Ability* ability); + + int newAuthorId() const; + Author* newAuthor(Author* author); + + int newBadgeId() const; + Badge* newBadge(Badge* badge); + + int newCoinListId() const; + CoinList* newCoinList(CoinList* coinList); + + int newEggGroupId() const; + EggGroup* newEggGroup(EggGroup* eggGroup); + + int newItemId() const; + Item* newItem(Item* item); + + int newItemTypeId() const; + ItemType* newItemType(ItemType* itemType); + + int newMapId() const; + Map* newMap(Map* map); + + int newMoveId() const; + Move* newMove(Move* move); + + int newNatureId() const; + Nature* newNature(Nature* nature); + + int newGlobalScriptId() const; + GlobalScript* newGlobalScript(GlobalScript* globalScript); + + int newSkinId() const; + Skin* newSkin(Skin* skin); + + int newSoundId() const; + Sound* newSound(Sound* sound); + + int newSpeciesId() const; + Species* newSpecies(Species* species); + + int newSpriteId() const; + Sprite* newSprite(Sprite* sprite); + + int newStatusId() const; + Status* newStatus(Status* status); + + int newStoreId() const; + Store* newStore(Store* store); + + int newTileId() const; + Tile* newTile(Tile* tile); + + int newTimeId() const; + Time* newTime(Time* time); + + int newTrainerId() const; + Trainer* newTrainer(Trainer* trainer); + + int newTypeId() const; + Type* newType(Type* type); + + int newWeatherId() const; + Weather* newWeather(Weather* weather); + + void clear(); + + QString m_title; + QString m_version; + QString m_description; + int m_startMap; + int m_startWarp; + Matrix<Fraction> m_typechart; + Rules* m_rules; + QList<Ability*> m_abilities; + QList<Author*> m_authors; + QList<Badge*> m_badges; + QList<CoinList*> m_coinLists; + QList<EggGroup*> m_eggGroups; + QList<GlobalScript*> m_globalScripts; + QList<Item*> m_items; + QList<ItemType*> m_itemTypes; + QList<Map*> m_maps; + QList<Move*> m_moves; + QList<Nature*> m_natures; + QList<Skin*> m_skins; + QList<Sound*> m_sounds; + QList<Species*> m_species; + QList<Sprite*> m_sprites; + QList<Status*> m_status; + QList<Store*> m_stores; + QList<Tile*> m_tiles; + QList<Time*> m_times; + QList<Trainer*> m_trainers; + QList<Type*> m_types; + QList<Weather*> m_weathers; +}; +} + +#endif diff --git a/sigmod/Rules.cpp b/sigmod/Rules.cpp new file mode 100644 index 00000000..b4a1836a --- /dev/null +++ b/sigmod/Rules.cpp @@ -0,0 +1,438 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Rules.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +const QStringList Pokemod::Rules::DVStr = QStringList() << "16" << "32"; + +Pokemod::Rules::Rules(const Rules& rules) : + Object(rules.parent(), 0) +{ + *this = rules; +} + +Pokemod::Rules::Rules(const Pokemod* parent) : + Object(parent, 0), + m_genderAllowed(false), + m_breedingAllowed(false), + m_criticalDomains(false), + m_useTurns(true), + m_numBoxes(0), + m_boxSize(1), + m_maxParty(1), + m_maxFight(1), + m_maxPlayers(2), + m_maxHeldItems(0), + m_maxAbilities(0), + m_maxNatures(0), + m_maxMoves(1), + m_maxLevel(1), + m_maxStages(6), + m_maxMoney(0), + m_hardCash(false), + m_allowSwitchStyle(false), + m_specialSplit(false), + m_specialDVSplit(false), + m_effortValuesAllowed(false), + m_maxTotalEV(0), + m_maxEVPerStat(0) +{ +} + +Pokemod::Rules::Rules(const Rules& rules, const Pokemod* parent) : + Object(parent, 0) +{ + *this = rules; +} + +Pokemod::Rules::Rules(const QDomElement& xml, const Pokemod* parent) : + Object(parent, 0) +{ + load(xml); +} + +void Pokemod::Rules::validate() +{ + TEST_BEGIN(); + TEST(setBreedingAllowed, breedingAllowed); + TEST(setNumBoxes, numBoxes); + TEST(setBoxSize, boxSize); + TEST(setMaxParty, maxParty); + TEST(setMaxFight, maxFight); + TEST(setMaxPlayers, maxPlayers); + TEST(setMaxMoves, maxMoves); + TEST(setMaxLevel, maxLevel); + if (!m_maxMoney) + emit(warning("Player cannot carry any money")); + if (m_effortValuesAllowed) + { + TEST(setMaxEVPerStat, maxEVPerStat); + } + TEST_END(); +} + +void Pokemod::Rules::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(genderAllowed); + LOAD(breedingAllowed); + LOAD(criticalDomains); + LOAD(useTurns); + LOAD(numBoxes); + LOAD(boxSize); + LOAD(maxParty); + LOAD(maxFight); + LOAD(maxPlayers); + LOAD(maxHeldItems); + LOAD(maxAbilities); + LOAD(maxNatures); + LOAD(maxMoves); + LOAD(maxLevel); + LOAD(maxStages); + LOAD(maxMoney); + LOAD(hardCash); + LOAD(allowSwitchStyle); + LOAD(specialSplit); + LOAD(specialDVSplit); + LOAD(effortValuesAllowed); + LOAD(maxTotalEV); + LOAD(maxEVPerStat); +} + +QDomElement Pokemod::Rules::save() const +{ + QDomElement xml = QDomDocument().createElement(className()); + SAVE(genderAllowed); + SAVE(breedingAllowed); + SAVE(criticalDomains); + SAVE(useTurns); + SAVE(numBoxes); + SAVE(boxSize); + SAVE(maxParty); + SAVE(maxFight); + SAVE(maxPlayers); + SAVE(maxHeldItems); + SAVE(maxAbilities); + SAVE(maxNatures); + SAVE(maxMoves); + SAVE(maxLevel); + SAVE(maxStages); + SAVE(maxMoney); + SAVE(hardCash); + SAVE(allowSwitchStyle); + SAVE(specialSplit); + SAVE(specialDVSplit); + SAVE(effortValuesAllowed); + SAVE(maxTotalEV); + SAVE(maxEVPerStat); + return xml; +} + +void Pokemod::Rules::setGenderAllowed(const bool genderAllowed) +{ + CHECK(genderAllowed); +} + +void Pokemod::Rules::setBreedingAllowed(const bool breedingAllowed) +{ + if (!m_genderAllowed && breedingAllowed) + emit(error(bounds("breedingAllowed"))); + else + CHECK(breedingAllowed); +} + +void Pokemod::Rules::setCriticalDomains(const bool criticalDomains) +{ + CHECK(criticalDomains); +} + +void Pokemod::Rules::setUseTurns(const bool useTurns) +{ + CHECK(useTurns); +} + +void Pokemod::Rules::setNumBoxes(const int numBoxes) +{ + CHECK(numBoxes); +} + +void Pokemod::Rules::setBoxSize(const int boxSize) +{ + if (m_numBoxes && !boxSize) + emit(error(bounds("boxSize"))); + else + CHECK(boxSize); +} + +void Pokemod::Rules::setMaxParty(const int maxParty) +{ + if (!maxParty) + emit(error(bounds("maxParty"))); + else + CHECK(maxParty); +} + +void Pokemod::Rules::setMaxFight(const int maxFight) +{ + if (m_maxParty < maxFight) + emit(error(bounds("maxFight"))); + else + CHECK(maxFight); +} + +void Pokemod::Rules::setMaxPlayers(const int maxPlayers) +{ + if (maxPlayers < 2) + emit(error(bounds("maxPlayers"))); + else + CHECK(maxPlayers); +} + +void Pokemod::Rules::setMaxHeldItems(const int maxHeldItems) +{ + CHECK(maxHeldItems); +} + +void Pokemod::Rules::setMaxAbilities(const int maxAbilities) +{ + CHECK(maxAbilities); +} + +void Pokemod::Rules::setMaxNatures(const int maxNatures) +{ + CHECK(maxNatures); +} + +void Pokemod::Rules::setMaxMoves(const int maxMoves) +{ + if (!maxMoves) + emit(error(bounds("maxMoves"))); + else + CHECK(maxMoves); +} + +void Pokemod::Rules::setMaxLevel(const int maxLevel) +{ + if (!maxLevel) + emit(error(bounds("maxLevel"))); + else + CHECK(maxLevel); +} + +void Pokemod::Rules::setMaxStages(const int maxStages) +{ + CHECK(maxStages); +} + +void Pokemod::Rules::setMaxMoney(const int maxMoney) +{ + CHECK(maxMoney); +} + +void Pokemod::Rules::setHardCash(const bool hardCash) +{ + CHECK(hardCash); +} + +void Pokemod::Rules::setAllowSwitchStyle(const bool allowSwitchStyle) +{ + CHECK(allowSwitchStyle); +} + +void Pokemod::Rules::setSpecialSplit(const bool specialSplit) +{ + CHECK(specialSplit); +} + +void Pokemod::Rules::setSpecialDVSplit(const bool specialDVSplit) +{ + if (!specialDVSplit && m_specialSplit) + emit(error(bounds("specialDVSplit"))); + else + CHECK(specialDVSplit); +} + +void Pokemod::Rules::setEffortValuesAllowed(const bool effortValuesAllowed) +{ + CHECK(effortValuesAllowed); +} + +void Pokemod::Rules::setMaxTotalEV(const int maxTotalEV) +{ + if (!maxTotalEV) + emit(error(bounds("maxTotalEV"))); + else + CHECK(maxTotalEV); +} + +void Pokemod::Rules::setMaxEVPerStat(const int maxEVPerStat) +{ + if ((!maxEVPerStat && m_maxTotalEV) || (m_maxTotalEV < maxEVPerStat)) + emit(error(bounds("maxEVPerStat"))); + else + CHECK(maxEVPerStat); +} + +bool Pokemod::Rules::genderAllowed() const +{ + return m_genderAllowed; +} + +bool Pokemod::Rules::breedingAllowed() const +{ + return m_breedingAllowed; +} + +bool Pokemod::Rules::criticalDomains() const +{ + return m_criticalDomains; +} + +bool Pokemod::Rules::useTurns() const +{ + return m_useTurns; +} + +int Pokemod::Rules::numBoxes() const +{ + return m_numBoxes; +} + +int Pokemod::Rules::boxSize() const +{ + return m_boxSize; +} + +int Pokemod::Rules::maxParty() const +{ + return m_maxParty; +} + +int Pokemod::Rules::maxFight() const +{ + return m_maxFight; +} + +int Pokemod::Rules::maxPlayers() const +{ + return m_maxPlayers; +} + +int Pokemod::Rules::maxHeldItems() const +{ + return m_maxHeldItems; +} + +int Pokemod::Rules::maxAbilities() const +{ + return m_maxAbilities; +} + +int Pokemod::Rules::maxNatures() const +{ + return m_maxNatures; +} + +int Pokemod::Rules::maxMoves() const +{ + return m_maxMoves; +} + +int Pokemod::Rules::maxLevel() const +{ + return m_maxLevel; +} + +int Pokemod::Rules::maxStages() const +{ + return m_maxStages; +} + +int Pokemod::Rules::maxMoney() const +{ + return m_maxMoney; +} + +bool Pokemod::Rules::hardCash() const +{ + return m_hardCash; +} + +bool Pokemod::Rules::allowSwitchStyle() const +{ + return m_allowSwitchStyle; +} + +bool Pokemod::Rules::specialSplit() const +{ + return m_specialSplit; +} + +bool Pokemod::Rules::specialDVSplit() const +{ + return m_specialDVSplit; +} + +bool Pokemod::Rules::effortValuesAllowed() const +{ + return m_effortValuesAllowed; +} + +int Pokemod::Rules::maxTotalEV() const +{ + return m_maxTotalEV; +} + +int Pokemod::Rules::maxEVPerStat() const +{ + return m_maxEVPerStat; +} + +Pokemod::Rules& Pokemod::Rules::operator=(const Rules& rhs) +{ + if (this == &rhs) + return *this; + COPY(genderAllowed); + COPY(breedingAllowed); + COPY(criticalDomains); + COPY(useTurns); + COPY(numBoxes); + COPY(boxSize); + COPY(maxParty); + COPY(maxFight); + COPY(maxPlayers); + COPY(maxHeldItems); + COPY(maxAbilities); + COPY(maxNatures); + COPY(maxMoves); + COPY(maxLevel); + COPY(maxStages); + COPY(maxMoney); + COPY(hardCash); + COPY(allowSwitchStyle); + COPY(specialSplit); + COPY(specialDVSplit); + COPY(effortValuesAllowed); + COPY(maxTotalEV); + COPY(maxEVPerStat); + return *this; +} diff --git a/sigmod/Rules.h b/sigmod/Rules.h new file mode 100644 index 00000000..54287ce0 --- /dev/null +++ b/sigmod/Rules.h @@ -0,0 +1,122 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_RULES__ +#define __POKEMOD_RULES__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Rules : public Object +{ + Q_OBJECT + + public: + static const QStringList DVStr; + + Rules(const Rules& rules); + Rules(const Pokemod* parent); + Rules(const Rules& rules, const Pokemod* parent); + Rules(const QDomElement& xml, const Pokemod* parent); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setGenderAllowed(const bool genderAllowed); + void setBreedingAllowed(const bool breedingAllowed); + void setCriticalDomains(const bool criticalDomains); + void setUseTurns(const bool useTurns); + void setNumBoxes(const int numBoxes); + void setBoxSize(const int boxSize); + void setMaxParty(const int maxParty); + void setMaxFight(const int maxFight); + void setMaxPlayers(const int maxPlayers); + void setMaxHeldItems(const int maxHeldItems); + void setMaxAbilities(const int maxAbilities); + void setMaxNatures(const int maxNatures); + void setMaxMoves(const int maxMoves); + void setMaxLevel(const int maxLevel); + void setMaxStages(const int maxStage); + void setMaxMoney(const int maxMoney); + void setHardCash(const bool hardCash); + void setAllowSwitchStyle(const bool allowSwitchStyle); + void setSpecialSplit(const bool specialSplit); + void setSpecialDVSplit(const bool specialDVSplit); + void setEffortValuesAllowed(const bool effortValues); + void setMaxTotalEV(const int maxTotalEV); + void setMaxEVPerStat(const int maxEVPerStat); + + bool genderAllowed() const; + bool breedingAllowed() const; + bool criticalDomains() const; + bool useTurns() const; + int numBoxes() const; + int boxSize() const; + int maxParty() const; + int maxFight() const; + int maxPlayers() const; + int maxHeldItems() const; + int maxAbilities() const; + int maxNatures() const; + int maxMoves() const; + int maxLevel() const; + int maxStages() const; + int maxMoney() const; + bool hardCash() const; + bool allowSwitchStyle() const; + bool specialSplit() const; + bool specialDVSplit() const; + bool effortValuesAllowed() const; + int maxTotalEV() const; + int maxEVPerStat() const; + + Rules& operator=(const Rules& rhs); + private: + bool m_genderAllowed; + bool m_breedingAllowed; + bool m_criticalDomains; + bool m_useTurns; + int m_numBoxes; + int m_boxSize; + int m_maxParty; + int m_maxFight; + int m_maxPlayers; + int m_maxHeldItems; + int m_maxAbilities; + int m_maxNatures; + int m_maxMoves; + int m_maxLevel; + int m_maxStages; + int m_maxMoney; + bool m_hardCash; + bool m_allowSwitchStyle; + bool m_specialSplit; + bool m_specialDVSplit; + bool m_effortValuesAllowed; + int m_maxTotalEV; + int m_maxEVPerStat; +}; +} + +#endif diff --git a/sigmod/Script.h b/sigmod/Script.h new file mode 100644 index 00000000..3633e0d3 --- /dev/null +++ b/sigmod/Script.h @@ -0,0 +1,103 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SCRIPT__ +#define __POKEMOD_SCRIPT__ + +// Pokemod includes +#include "Global.h" + +// Qt includes +#include <QtCore/QString> + +namespace Pokemod +{ +class POKEMOD_EXPORT Script +{ + public: + Script(); + Script(const QString& interpreter, const QString& script); + + void setInterpreter(const QString& interpreter); + void setScript(const QString& script); + + QString interpreter() const; + QString script() const; + + Script& operator=(const Script& rhs); + bool operator==(const Script& rhs) const; + bool operator!=(const Script& rhs) const; + private: + QString m_interpreter; + QString m_script; +}; + +inline Script::Script() : + m_interpreter(""), + m_script("") +{ +} + +inline Script::Script(const QString& interpreter, const QString& script) : + m_interpreter(interpreter), + m_script(script) +{ +} + +inline void Script::setInterpreter(const QString& interpreter) +{ + m_interpreter = interpreter; +} + +inline void Script::setScript(const QString& script) +{ + m_script = script; +} + +inline QString Script::interpreter() const +{ + return m_interpreter; +} + +inline QString Script::script() const +{ + return m_script; +} + +inline Script& Script::operator=(const Script& rhs) +{ + if (this == &rhs) + return *this; + m_interpreter = rhs.m_interpreter; + m_script = rhs.m_script; + return *this; +} + +inline bool Script::operator==(const Script& rhs) const +{ + return ((m_interpreter == rhs.m_interpreter) && (m_script == rhs.m_script)); +} + +inline bool Script::operator!=(const Script& rhs) const +{ + return !(*this == rhs); +} + +} +Q_DECLARE_METATYPE(Pokemod::Script) + +#endif diff --git a/sigmod/Skin.cpp b/sigmod/Skin.cpp new file mode 100644 index 00000000..b352acd6 --- /dev/null +++ b/sigmod/Skin.cpp @@ -0,0 +1,102 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Skin.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Script.h" + +Pokemod::Skin::Skin(const Skin& skin) : + Object(skin.parent(), skin.id()) +{ + *this = skin; +} + +Pokemod::Skin::Skin(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_script("", "") +{ +} + +Pokemod::Skin::Skin(const Skin& skin, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = skin; +} + +Pokemod::Skin::Skin(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Skin::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::Skin::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(script); +} + +QDomElement Pokemod::Skin::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(script); + return xml; +} + +void Pokemod::Skin::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Skin::setScript(const Script& script) +{ + CHECK(script); +} + +QString Pokemod::Skin::name() const +{ + return m_name; +} + +Pokemod::Script Pokemod::Skin::script() const +{ + return m_script; +} + +Pokemod::Skin& Pokemod::Skin::operator=(const Skin& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(script); + return *this; +} diff --git a/sigmod/Skin.h b/sigmod/Skin.h new file mode 100644 index 00000000..b3bfd2d2 --- /dev/null +++ b/sigmod/Skin.h @@ -0,0 +1,58 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SKIN__ +#define __POKEMOD_SKIN__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Skin : public Object +{ + Q_OBJECT + + public: + Skin(const Skin& skin); + Skin(const Pokemod* parent, const int id); + Skin(const Skin& skin, const Pokemod* parent, const int id); + Skin(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setScript(const Script& script); + + QString name() const; + Script script() const; + + Skin& operator=(const Skin& rhs); + private: + QString m_name; + Script m_script; +}; +} + +#endif diff --git a/sigmod/Sound.cpp b/sigmod/Sound.cpp new file mode 100644 index 00000000..a625274f --- /dev/null +++ b/sigmod/Sound.cpp @@ -0,0 +1,120 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Sound.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +const QStringList Pokemod::Sound::TypeStr = QStringList() << "Sound Effect" << "Music"; + +Pokemod::Sound::Sound(const Sound& sound) : + Object(sound.parent(), sound.id()) +{ + *this = sound; +} + +Pokemod::Sound::Sound(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_type(SoundEffect), + m_data() +{ +} + +Pokemod::Sound::Sound(const Sound& sound, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = sound; +} + +Pokemod::Sound::Sound(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Sound::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + if (m_data.isEmpty()) + emit(error("Data is empty")); + TEST_END(); +} + +void Pokemod::Sound::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(type); + LOAD(data); +} + +QDomElement Pokemod::Sound::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(type); + SAVE(data); + return xml; +} + +void Pokemod::Sound::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Sound::setType(const Type type) +{ + CHECK(type); +} + +void Pokemod::Sound::setData(const QByteArray& data) +{ + CHECK(data); +} + +QString Pokemod::Sound::name() const +{ + return m_name; +} + +Pokemod::Sound::Type Pokemod::Sound::type() const +{ + return m_type; +} + +QByteArray Pokemod::Sound::data() const +{ + return m_data; +} + +Pokemod::Sound& Pokemod::Sound::operator=(const Sound& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(name); + COPY(type); + COPY(data); + return *this; +} diff --git a/sigmod/Sound.h b/sigmod/Sound.h new file mode 100644 index 00000000..0f4033ce --- /dev/null +++ b/sigmod/Sound.h @@ -0,0 +1,73 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SOUND__ +#define __POKEMOD_SOUND__ + +// Pokemod includes +#include "Object.h" + +// Qt includes +#include <QtCore/QByteArray> +#include <QtCore/QString> + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Sound : public Object +{ + Q_OBJECT + Q_ENUMS(Type) + + public: + enum Type + { + SoundEffect = 0, + Music = 1 + }; + static const QStringList TypeStr; + + Sound(const Sound& sound); + Sound(const Pokemod* parent, const int id); + Sound(const Sound& sound, const Pokemod* parent, const int id); + Sound(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setType(const Type type); + void setData(const QByteArray& data); + + QString name() const; + Type type() const; + QByteArray data() const; + + Sound& operator=(const Sound& rhs); + private: + QString m_name; + Type m_type; + QByteArray m_data; +}; +} +Q_DECLARE_METATYPE(Pokemod::Sound::Type) + +#endif diff --git a/sigmod/Species.cpp b/sigmod/Species.cpp new file mode 100644 index 00000000..bab59446 --- /dev/null +++ b/sigmod/Species.cpp @@ -0,0 +1,861 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Species.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Rules.h" +#include "SpeciesAbility.h" +#include "SpeciesItem.h" +#include "SpeciesMove.h" + +// Qt includes +#include <QtCore/QSet> + +const QStringList Pokemod::Species::StyleStr = QStringList() << "Fluctuating" << "Fading" << "Slow" << "Normal" << "Fast" << "Erratic"; + +Pokemod::Species::Species(const Species& species) : + Object(species.parent(), species.id()), + m_baseStat(ST_End_GSC), + m_effortValue(ST_End_GSC) +{ + *this = species; +} + +Pokemod::Species::Species(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_baseStat(ST_End_GSC), + m_effortValue(ST_End_GSC), + m_growth(Normal), + m_catchValue(0), + m_runChance(1, 1), + m_fleeChance(1, 1), + m_itemChance(1, 1), + m_pokedexNumber(INT_MAX), + m_weight(0), + m_height(0), + m_frontMaleSprite(-1), + m_backMaleSprite(-1), + m_frontFemaleSprite(-1), + m_backFemaleSprite(-1), + m_skin(-1), + m_pokedexEntry(""), + m_genderFactor(1, 1), + m_eggSpecies(INT_MAX), + m_eggSteps(0), + m_evolution("", "") +{ + for (int i = 0; i < m_baseStat.size(); ++i) + m_baseStat[i] = 0; + for (int i = 0; i < m_effortValue.size(); ++i) + m_effortValue[i] = 0; +} + +Pokemod::Species::Species(const Species& species, const Pokemod* parent, const int id) : + Object(parent, id), + m_baseStat(ST_End_GSC), + m_effortValue(ST_End_GSC) +{ + *this = species; +} + +Pokemod::Species::Species(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id), + m_baseStat(ST_End_GSC), + m_effortValue(ST_End_GSC) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::Species::~Species() +{ + clear(); +} + +void Pokemod::Species::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_ARRAY(setEffortValue, effortValue, ST_End_GSC); + TEST(setGrowth, growth); + TEST(setRunChance, runChance); + TEST(setFleeChance, fleeChance); + TEST(setItemChance, itemChance); + TEST(setWeight, weight); + TEST(setFrontMaleSprite, frontMaleSprite); + TEST(setBackMaleSprite, backMaleSprite); + TEST(setFrontFemaleSprite, frontFemaleSprite); + TEST(setBackFemaleSprite, backFemaleSprite); + TEST(setSkin, skin); + if ((m_pokedexNumber != INT_MAX) && m_pokedexEntry.isEmpty()) + emit(error("Pokedex entry is empty")); + TEST(setGenderFactor, genderFactor); + if (qobject_cast<const Pokemod*>(pokemod())->rules()->breedingAllowed()) + { + if (qobject_cast<const Pokemod*>(pokemod())->speciesIndex(m_eggSpecies) == INT_MAX) + emit(error(bounds("egg species"))); + else + { + if (qobject_cast<const Pokemod*>(pokemod())->species(m_eggSpecies)->growth() != m_growth) + emit(error("Growth mismatch with egg species")); + TEST(setEggSteps, eggSteps); + } + } + TEST_LIST(setType, type); + TEST_LIST(setEggGroup, eggGroup); + QSet<int> idChecker; + QSet<int> valueChecker; + if (abilityCount() < qobject_cast<const Pokemod*>(pokemod())->rules()->maxAbilities()) + emit(warning("There are too few abilities")); + TEST_SUB_BEGIN(SpeciesAbility, abilities); + TEST_SUB("ability", id); + TEST_SUB_RAW(value, "ability", ability); + TEST_SUB_END(); + idChecker.clear(); + valueChecker.clear(); + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxHeldItems() && !itemCount()) + emit(warning("There are no items")); + TEST_SUB_BEGIN(SpeciesItem, items); + TEST_SUB("item", id); + TEST_SUB_RAW(value, "item", item); + TEST_SUB_END(); + idChecker.clear(); + valueChecker.clear(); + if (!moveCount()) + emit(error("There are no moves")); + TEST_SUB_BEGIN(SpeciesMove, moves); + TEST_SUB("move", id); + TEST_SUB_RAW(value, "move", move); + TEST_SUB_END(); + TEST_END(); +} + +void Pokemod::Species::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD_ARRAY(baseStat); + LOAD_ARRAY(effortValue); + LOAD(growth); + LOAD(experienceValue); + LOAD(catchValue); + LOAD(runChance); + LOAD(fleeChance); + LOAD(itemChance); + LOAD(pokedexNumber); + LOAD(weight); + LOAD(height); + LOAD(frontMaleSprite); + LOAD(backMaleSprite); + LOAD(frontFemaleSprite); + LOAD(backFemaleSprite); + LOAD(skin); + LOAD(pokedexEntry); + LOAD(genderFactor); + LOAD(eggSpecies); + LOAD(eggSteps); + LOAD_LIST(type); + LOAD_LIST(eggGroup); + LOAD(evolution); + LOAD_SUB(newAbility, SpeciesAbility); + LOAD_SUB(newItem, SpeciesItem); + LOAD_SUB(newMove, SpeciesMove); +} + +QDomElement Pokemod::Species::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE_ARRAY(baseStat); + SAVE_ARRAY(effortValue); + SAVE(growth); + SAVE(experienceValue); + SAVE(catchValue); + SAVE(runChance); + SAVE(fleeChance); + SAVE(itemChance); + SAVE(pokedexNumber); + SAVE(weight); + SAVE(height); + SAVE(frontMaleSprite); + SAVE(backMaleSprite); + SAVE(frontFemaleSprite); + SAVE(backFemaleSprite); + SAVE(skin); + SAVE(pokedexEntry); + SAVE(genderFactor); + SAVE(eggSpecies); + SAVE(eggSteps); + SAVE_LIST( type); + SAVE_LIST(eggGroup); + SAVE(evolution); + SAVE_SUB(SpeciesAbility, abilities); + SAVE_SUB(SpeciesItem, items); + SAVE_SUB(SpeciesMove, moves); + return xml; +} + +void Pokemod::Species::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Species::setBaseStat(const Stat stat, const int baseStat) +{ + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_HP ... ST_Special: + break; + default: + emit(warning(bounds("stat"))); + return; + } + CHECK_ARRAY(baseStat[stat], baseStat); +} + +void Pokemod::Species::setEffortValue(const Stat stat, const int effortValue) +{ + if (!qobject_cast<const Pokemod*>(pokemod())->rules()->effortValuesAllowed()) + emit(error("Effort Values not allowed")); + else if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxEVPerStat() < effortValue) + emit(error(bounds("effortValue"))); + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_HP ... ST_Special: + break; + default: + emit(warning(bounds("stat"))); + return; + } + CHECK_ARRAY(effortValue[stat], effortValue); +} + +void Pokemod::Species::setEffortValue(const int effortValue) +{ + if (qobject_cast<const Pokemod*>(pokemod())->rules()->effortValuesAllowed() && qobject_cast<const Pokemod*>(pokemod())->rules()->maxEVPerStat() < effortValue) + emit(error(bounds("effortValue"))); +} + +void Pokemod::Species::setGrowth(const Style growth) +{ + CHECK(growth); +} + +void Pokemod::Species::setExperienceValue(const int experienceValue) +{ + CHECK(experienceValue); +} + +void Pokemod::Species::setCatchValue(const int catchValue) +{ + if (255 < catchValue) + emit(error(bounds("catchValue"))); + else + CHECK(catchValue); +} + +void Pokemod::Species::setRunChance(const Fraction& runChance) +{ + if (1 < runChance) + emit(error(bounds("runChance"))); + else + CHECK(runChance); +} + +void Pokemod::Species::setFleeChance(const Fraction& fleeChance) +{ + if (1 < fleeChance) + emit(error(bounds("fleeChance"))); + else + CHECK(fleeChance); +} + +void Pokemod::Species::setItemChance(const Fraction& itemChance) +{ + if (1 < itemChance) + emit(error(bounds("itemChance"))); + else + CHECK(itemChance); +} + +void Pokemod::Species::setPokedexNumber(const int pokedexNumber) +{ + CHECK(pokedexNumber); +} + +void Pokemod::Species::setWeight(const int weight) +{ + CHECK(weight); +} + +void Pokemod::Species::setHeight(const int height) +{ + CHECK(height); +} + +void Pokemod::Species::setPokedexEntry(const QString& pokedexEntry) +{ + CHECK(pokedexEntry); +} + +void Pokemod::Species::setFrontMaleSprite(const int frontMaleSprite) +{ + if (m_genderFactor.numerator() == m_genderFactor.denominator()) + emit(error("Cannot be male")); + else if (qobject_cast<const Pokemod*>(pokemod())->spriteIndex(frontMaleSprite) == INT_MAX) + emit(error(bounds("frontMaleSprite"))); + else + CHECK(frontMaleSprite); +} + +void Pokemod::Species::setBackMaleSprite(const int backMaleSprite) +{ + if (m_genderFactor.numerator() == m_genderFactor.denominator()) + emit(error("Cannot be male")); + else if (qobject_cast<const Pokemod*>(pokemod())->spriteIndex(backMaleSprite) == INT_MAX) + emit(error(bounds("backMaleSprite"))); + else + CHECK(backMaleSprite); +} + +void Pokemod::Species::setFrontFemaleSprite(const int frontFemaleSprite) +{ + if (!qobject_cast<const Pokemod*>(pokemod())->rules()->genderAllowed()) + emit(error("Gender is not allowed")); + else if (!m_genderFactor.numerator()) + emit(error("Cannot be female")); + else if (1 < m_genderFactor) + emit(error("Genderless uses male sprites")); + else if (qobject_cast<const Pokemod*>(pokemod())->spriteIndex(frontFemaleSprite) == INT_MAX) + emit(error(bounds("frontFemaleSprite"))); + else + CHECK(frontFemaleSprite); +} + +void Pokemod::Species::setBackFemaleSprite(const int backFemaleSprite) +{ + if (!qobject_cast<const Pokemod*>(pokemod())->rules()->genderAllowed()) + emit(error("Gender is not allowed")); + else if (!m_genderFactor.numerator()) + emit(error("Cannot be female")); + else if (1 < m_genderFactor) + emit(error("Genderless uses male sprites")); + else if (qobject_cast<const Pokemod*>(pokemod())->spriteIndex(backFemaleSprite) == INT_MAX) + emit(error(bounds("backFemaleSprite"))); + else + CHECK(backFemaleSprite); +} + +void Pokemod::Species::setSkin(const int skin) +{ + if (qobject_cast<const Pokemod*>(pokemod())->skinIndex(skin) == INT_MAX) + emit(error(bounds("skin"))); + else + CHECK(skin); +} + +void Pokemod::Species::setGenderFactor(const Fraction& genderFactor) +{ + CHECK(genderFactor); +} + +void Pokemod::Species::setEggSpecies(const int eggSpecies) +{ + if (qobject_cast<const Pokemod*>(pokemod())->speciesIndex(eggSpecies) == INT_MAX) + emit(error(bounds("eggSpecies"))); + else + CHECK(eggSpecies); +} + +void Pokemod::Species::setEggSteps(const int eggSteps) +{ + CHECK(eggSteps); +} + +void Pokemod::Species::setType(const int type, const bool state) +{ + if (qobject_cast<const Pokemod*>(pokemod())->typeIndex(type) == INT_MAX) + emit(error(bounds("type"))); + else if (state && !m_type.contains(type)) + { + m_type.append(type); + emit(changed()); + } + else if (m_type.contains(type)) + { + m_type.removeAll(type); + emit(changed()); + } +} + +void Pokemod::Species::setEggGroup(const int eggGroup, const bool state) +{ + if (qobject_cast<const Pokemod*>(pokemod())->eggGroupIndex(eggGroup) == INT_MAX) + emit(error(bounds("egg group"))); + else if (state && !m_eggGroup.contains(eggGroup)) + { + m_eggGroup.append(eggGroup); + emit(changed()); + } + else if (m_eggGroup.contains(eggGroup)) + { + m_eggGroup.removeAll(eggGroup); + emit(changed()); + } +} + +void Pokemod::Species::setEvolution(const Script& evolution) +{ + CHECK(evolution); +} + +QString Pokemod::Species::name() const +{ + return m_name; +} + +int Pokemod::Species::baseStat(const Stat stat) const +{ + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_HP ... ST_Special: + return m_effortValue[stat]; + default: + emit(warning(bounds("base stat"))); + return -1; + } +} + +int Pokemod::Species::effortValue(const Stat stat) const +{ + switch (stat) + { + case ST_SpecialDefense: + if (qobject_cast<const Pokemod*>(pokemod())->rules()->specialSplit()) + case ST_HP ... ST_Special: + return m_effortValue[stat]; + default: + emit(warning(bounds("effort value"))); + return -1; + } +} + +Pokemod::Species::Style Pokemod::Species::growth() const +{ + return m_growth; +} + +int Pokemod::Species::experienceValue() const +{ + return m_experienceValue; +} + +int Pokemod::Species::catchValue() const +{ + return m_catchValue; +} + +Pokemod::Fraction Pokemod::Species::runChance() const +{ + return m_runChance; +} + +Pokemod::Fraction Pokemod::Species::fleeChance() const +{ + return m_fleeChance; +} + +Pokemod::Fraction Pokemod::Species::itemChance() const +{ + return m_itemChance; +} + +int Pokemod::Species::pokedexNumber() const +{ + return m_pokedexNumber; +} + +int Pokemod::Species::weight() const +{ + return m_weight; +} + +int Pokemod::Species::height() const +{ + return m_height; +} + +QString Pokemod::Species::pokedexEntry() const +{ + return m_pokedexEntry; +} + +int Pokemod::Species::frontMaleSprite() const +{ + return m_frontMaleSprite; +} + +int Pokemod::Species::backMaleSprite() const +{ + return m_backMaleSprite; +} + +int Pokemod::Species::frontFemaleSprite() const +{ + return m_frontFemaleSprite; +} + +int Pokemod::Species::backFemaleSprite() const +{ + return m_backFemaleSprite; +} + +int Pokemod::Species::skin() const +{ + return m_skin; +} + +Pokemod::Fraction Pokemod::Species::genderFactor() const +{ + return m_genderFactor; +} + +int Pokemod::Species::eggSpecies() const +{ + return m_eggSpecies; +} + +int Pokemod::Species::eggSteps() const +{ + return m_eggSteps; +} + +bool Pokemod::Species::type(const int type) const +{ + return m_type.contains(type); +} + +QList<int> Pokemod::Species::types() const +{ + return m_type; +} + +bool Pokemod::Species::eggGroup(const int eggGroup) const +{ + return m_eggGroup.contains(eggGroup); +} + +QList<int> Pokemod::Species::eggGroups() const +{ + return m_eggGroup; +} + +Pokemod::Script Pokemod::Species::evolution() const +{ + return m_evolution; +} + +const Pokemod::SpeciesAbility* Pokemod::Species::ability(const int index) const +{ + Q_ASSERT(index < abilityCount()); + return m_abilities.at(index); +} + +Pokemod::SpeciesAbility* Pokemod::Species::ability(const int index) +{ + Q_ASSERT(index < abilityCount()); + return m_abilities[index]; +} + +const Pokemod::SpeciesAbility* Pokemod::Species::abilityById(const int id) const +{ + return ability(abilityIndex(id)); +} + +Pokemod::SpeciesAbility* Pokemod::Species::abilityById(const int id) +{ + return ability(abilityIndex(id)); +} + +int Pokemod::Species::abilityIndex(const int id) const +{ + for (int i = 0; i < abilityCount(); ++i) + { + if (m_abilities[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Species::abilityCount() const +{ + return m_abilities.size(); +} + +Pokemod::SpeciesAbility* Pokemod::Species::newAbility() +{ + return newAbility(new SpeciesAbility(this, newAbilityId())); +} + +Pokemod::SpeciesAbility* Pokemod::Species::newAbility(const QDomElement& xml) +{ + return newAbility(new SpeciesAbility(xml, this, newAbilityId())); +} + +Pokemod::SpeciesAbility* Pokemod::Species::newAbility(const SpeciesAbility& ability) +{ + return newAbility(new SpeciesAbility(ability, this, newAbilityId())); +} + +Pokemod::SpeciesAbility* Pokemod::Species::newAbility(SpeciesAbility* ability) +{ + m_abilities.append(ability); + return ability; +} + +void Pokemod::Species::deleteAbility(const int index) +{ + Q_ASSERT(index < abilityCount()); + delete m_abilities[index]; + m_abilities.removeAt(index); +} + +void Pokemod::Species::deleteAbilityById(const int id) +{ + deleteAbility(abilityIndex(id)); +} + +int Pokemod::Species::newAbilityId() const +{ + int i = 0; + while ((i < abilityCount()) && (abilityIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::SpeciesItem* Pokemod::Species::item(const int index) const +{ + Q_ASSERT(index < itemCount()); + return m_items.at(index); +} + +Pokemod::SpeciesItem* Pokemod::Species::item(const int index) +{ + Q_ASSERT(index < itemCount()); + return m_items[index]; +} + +const Pokemod::SpeciesItem* Pokemod::Species::itemById(const int id) const +{ + return item(itemIndex(id)); +} + +Pokemod::SpeciesItem* Pokemod::Species::itemById(const int id) +{ + return item(itemIndex(id)); +} + +int Pokemod::Species::itemIndex(const int id) const +{ + for (int i = 0; i < itemCount(); ++i) + { + if (m_items[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Species::itemCount() const +{ + return m_items.size(); +} + +Pokemod::SpeciesItem* Pokemod::Species::newItem() +{ + return newItem(new SpeciesItem(this, newItemId())); +} + +Pokemod::SpeciesItem* Pokemod::Species::newItem(const QDomElement& xml) +{ + return newItem(new SpeciesItem(xml, this, newItemId())); +} + +Pokemod::SpeciesItem* Pokemod::Species::newItem(const SpeciesItem& item) +{ + return newItem(new SpeciesItem(item, this, newItemId())); +} + +Pokemod::SpeciesItem* Pokemod::Species::newItem(SpeciesItem* item) +{ + m_items.append(item); + return item; +} + +void Pokemod::Species::deleteItem(const int index) +{ + Q_ASSERT(index < itemCount()); + delete m_items[index]; + m_items.removeAt(index); +} + +void Pokemod::Species::deleteItemById(const int id) +{ + deleteItem(itemIndex(id)); +} + +int Pokemod::Species::newItemId() const +{ + int i = 0; + while ((i < itemCount()) && (itemIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Pokemod::SpeciesMove* Pokemod::Species::move(const int index) const +{ + Q_ASSERT(index < moveCount()); + return m_moves.at(index); +} + +Pokemod::SpeciesMove* Pokemod::Species::move(const int index) +{ + Q_ASSERT(index < moveCount()); + return m_moves[index]; +} + +const Pokemod::SpeciesMove* Pokemod::Species::moveById(const int id) const +{ + return move(moveIndex(id)); +} + +Pokemod::SpeciesMove* Pokemod::Species::moveById(const int id) +{ + return move(moveIndex(id)); +} + +int Pokemod::Species::moveIndex(const int id) const +{ + for (int i = 0; i < moveCount(); ++i) + { + if (m_moves[i]->id() == id) + return i; + } + return INT_MAX; +} + +int Pokemod::Species::moveCount() const +{ + return m_moves.size(); +} + +Pokemod::SpeciesMove* Pokemod::Species::newMove() +{ + return newMove(new SpeciesMove(this, newMoveId())); +} + +Pokemod::SpeciesMove* Pokemod::Species::newMove(const QDomElement& xml) +{ + return newMove(new SpeciesMove(xml, this, newMoveId())); +} + +Pokemod::SpeciesMove* Pokemod::Species::newMove(const SpeciesMove& move) +{ + return newMove(new SpeciesMove(move, this, newMoveId())); +} + +Pokemod::SpeciesMove* Pokemod::Species::newMove(SpeciesMove* move) +{ + m_moves.append(move); + return move; +} + +void Pokemod::Species::deleteMove(const int index) +{ + Q_ASSERT(index < moveCount()); + delete m_moves[index]; + m_moves.removeAt(index); +} + +void Pokemod::Species::deleteMoveById(const int id) +{ + deleteMove(moveIndex(id)); +} + +int Pokemod::Species::newMoveId() const +{ + int i = 0; + while ((i < moveCount()) && (moveIndex(i) != INT_MAX)) + ++i; + return i; +} + +Pokemod::Species& Pokemod::Species::operator=(const Species& rhs) +{ + if (this == &rhs) + return *this; + clear(); + COPY(name); + COPY(baseStat); + COPY(effortValue); + COPY(growth); + COPY(experienceValue); + COPY(catchValue); + COPY(runChance); + COPY(fleeChance); + COPY(itemChance); + COPY(pokedexNumber); + COPY(weight); + COPY(height); + COPY(frontMaleSprite); + COPY(backMaleSprite); + COPY(frontFemaleSprite); + COPY(backFemaleSprite); + COPY(skin); + COPY(pokedexEntry); + COPY(genderFactor); + COPY(eggSpecies); + COPY(eggSteps); + COPY(type); + COPY(eggGroup); + COPY(evolution); + COPY_SUB(SpeciesAbility, abilities); + COPY_SUB(SpeciesItem, items); + COPY_SUB(SpeciesMove, moves); + return *this; +} + +void Pokemod::Species::clear() +{ + while (abilityCount()) + deleteAbility(0); + while (itemCount()) + deleteItem(0); + while (moveCount()) + deleteMove(0); +} diff --git a/sigmod/Species.h b/sigmod/Species.h new file mode 100644 index 00000000..d63fb4ec --- /dev/null +++ b/sigmod/Species.h @@ -0,0 +1,199 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SPECIES__ +#define __POKEMOD_SPECIES__ + +// Pokemod includes +#include "Fraction.h" +#include "Object.h" +#include "Script.h" + +// Qt includes +#include <QtCore/QList> + +namespace Pokemod +{ +// Forward declarations +class Pokemod; +class SpeciesAbility; +class SpeciesItem; +class SpeciesMove; + +class POKEMOD_EXPORT Species : public Object +{ + Q_OBJECT + Q_ENUMS(Style) + + public: + enum Style + { + Fluctuating = 0, + Fading = 1, + Slow = 2, + Normal = 3, + Fast = 5, + Erratic = 6 + }; + static const QStringList StyleStr; + + Species(const Species& species); + Species(const Pokemod* parent, const int id); + Species(const Species& species, const Pokemod* parent, const int id); + Species(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~Species(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setBaseStat(const Stat stat, const int base); + void setEffortValue(const Stat stat, const int effortValue); + void setGrowth(const Style growth); + void setExperienceValue(const int experienceValue); + void setCatchValue(const int catchValue); + void setRunChance(const Fraction& runChance); + void setFleeChance(const Fraction& fleeChance); + void setItemChance(const Fraction& itemChance); + void setPokedexNumber(const int pokedexNumber); + void setWeight(const int weight); + void setHeight(const int height); + void setPokedexEntry(const QString& pokedexEntry); + void setFrontMaleSprite(const int frontMaleSprite); + void setBackMaleSprite(const int backMaleSprite); + void setFrontFemaleSprite(const int frontFemaleSprite); + void setBackFemaleSprite(const int backFemaleSprite); + void setGenderFactor(const Fraction& genderFactor); + void setSkin(const int skin); + void setEggSpecies(const int eggSpecies); + void setEggSteps(const int eggSteps); + void setType(const int type, const bool state); + void setEggGroup(const int eggGroup, const bool state); + void setEvolution(const Script& evolution); + + QString name() const; + int baseStat(const Stat stat) const; + int effortValue(const Stat stat) const; + Style growth() const; + int experienceValue() const; + int catchValue() const; + Fraction runChance() const; + Fraction fleeChance() const; + Fraction itemChance() const; + int pokedexNumber() const; + int weight() const; + int height() const; + QString pokedexEntry() const; + int frontMaleSprite() const; + int backMaleSprite() const; + int frontFemaleSprite() const; + int backFemaleSprite() const; + int skin() const; + Fraction genderFactor() const; + int eggSpecies() const; + int eggSteps() const; + bool type(const int type) const; + QList<int> types() const; + bool eggGroup(const int eggGroup) const; + QList<int> eggGroups() const; + Script evolution() const; + + const SpeciesAbility* ability(const int index) const; + SpeciesAbility* ability(const int index); + const SpeciesAbility* abilityById(const int id) const; + SpeciesAbility* abilityById(const int id); + int abilityIndex(const int id) const; + int abilityCount() const; + SpeciesAbility* newAbility(); + SpeciesAbility* newAbility(const QDomElement& xml); + SpeciesAbility* newAbility(const SpeciesAbility& ability); + void deleteAbility(const int index); + void deleteAbilityById(const int id); + + const SpeciesItem* item(const int index) const; + SpeciesItem* item(const int index); + const SpeciesItem* itemById(const int i) const; + SpeciesItem* itemById(const int i); + int itemIndex(const int id) const; + int itemCount() const; + SpeciesItem* newItem(); + SpeciesItem* newItem(const QDomElement& xml); + SpeciesItem* newItem(const SpeciesItem& item); + void deleteItem(const int index); + void deleteItemById(const int id); + + const SpeciesMove* move(const int index) const; + SpeciesMove* move(const int index); + const SpeciesMove* moveById(const int id) const; + SpeciesMove* moveById(const int id); + int moveIndex(const int id) const; + int moveCount() const; + SpeciesMove* newMove(); + SpeciesMove* newMove(const QDomElement& xml); + SpeciesMove* newMove(const SpeciesMove& move); + void deleteMove(const int index); + void deleteMoveById(const int id); + + Species& operator=(const Species& rhs); + private: + void setEffortValue(const int effortValue); + + int newAbilityId() const; + SpeciesAbility* newAbility(SpeciesAbility* ability); + + int newItemId() const; + SpeciesItem* newItem(SpeciesItem* item); + + int newMoveId() const; + SpeciesMove* newMove(SpeciesMove* move); + + void clear(); + + QString m_name; + QVarLengthArray<bool, ST_End_GSC> m_baseStat; + QVarLengthArray<bool, ST_End_GSC> m_effortValue; + Style m_growth; + int m_experienceValue; + int m_catchValue; + Fraction m_runChance; + Fraction m_fleeChance; + Fraction m_itemChance; + int m_pokedexNumber; + int m_weight; + int m_height; + int m_frontMaleSprite; + int m_backMaleSprite; + int m_frontFemaleSprite; + int m_backFemaleSprite; + int m_skin; + QString m_pokedexEntry; + Fraction m_genderFactor; + int m_eggSpecies; + int m_eggSteps; + QList<int> m_type; + QList<int> m_eggGroup; + Script m_evolution; + QList<SpeciesAbility*> m_abilities; + QList<SpeciesItem*> m_items; + QList<SpeciesMove*> m_moves; +}; +} +Q_DECLARE_METATYPE(Pokemod::Species::Style) + +#endif diff --git a/sigmod/SpeciesAbility.cpp b/sigmod/SpeciesAbility.cpp new file mode 100644 index 00000000..a95e0358 --- /dev/null +++ b/sigmod/SpeciesAbility.cpp @@ -0,0 +1,108 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "SpeciesAbility.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Species.h" + +Pokemod::SpeciesAbility::SpeciesAbility(const SpeciesAbility& ability) : + Object(ability.parent(), ability.id()) +{ + *this = ability; +} + +Pokemod::SpeciesAbility::SpeciesAbility(const Species* parent, const int id) : + Object(parent, id), + m_ability(INT_MAX), + m_weight(1) +{ +} + +Pokemod::SpeciesAbility::SpeciesAbility(const SpeciesAbility& ability, const Species* parent, const int id) : + Object(parent, id) +{ + *this = ability; +} + +Pokemod::SpeciesAbility::SpeciesAbility(const QDomElement& xml, const Species* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::SpeciesAbility::validate() +{ + TEST_BEGIN(); + TEST(setAbility, ability); + TEST(setWeight, weight); + TEST_END(); +} + +void Pokemod::SpeciesAbility::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(ability); + LOAD(weight); +} + +QDomElement Pokemod::SpeciesAbility::save() const +{ + SAVE_CREATE(); + SAVE(ability); + SAVE(weight); + return xml; +} + +void Pokemod::SpeciesAbility::setAbility(const int ability) +{ + if (qobject_cast<const Pokemod*>(pokemod())->abilityIndex(ability) == INT_MAX) + emit(error(bounds("ability"))); + else + CHECK(ability); +} + +void Pokemod::SpeciesAbility::setWeight(const int weight) +{ + if (!weight) + emit(error(bounds("weight"))); + else + CHECK(weight); +} + +int Pokemod::SpeciesAbility::ability() const +{ + return m_ability; +} + +int Pokemod::SpeciesAbility::weight() const +{ + return m_weight; +} + +Pokemod::SpeciesAbility& Pokemod::SpeciesAbility::operator=(const SpeciesAbility& rhs) +{ + if (this == &rhs) + return *this; + COPY(ability); + COPY(weight); + return *this; +} diff --git a/sigmod/SpeciesAbility.h b/sigmod/SpeciesAbility.h new file mode 100644 index 00000000..346f974a --- /dev/null +++ b/sigmod/SpeciesAbility.h @@ -0,0 +1,57 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SPECIESABILITY__ +#define __POKEMOD_SPECIESABILITY__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Species; + +class POKEMOD_EXPORT SpeciesAbility : public Object +{ + Q_OBJECT + + public: + SpeciesAbility(const SpeciesAbility& ability); + SpeciesAbility(const Species* parent, const int id); + SpeciesAbility(const SpeciesAbility& ability, const Species* parent, const int id); + SpeciesAbility(const QDomElement& xml, const Species* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setAbility(const int ability); + void setWeight(const int weight); + + int ability() const; + int weight() const; + + SpeciesAbility& operator=(const SpeciesAbility& rhs); + private: + int m_ability; + int m_weight; +}; +} + +#endif diff --git a/sigmod/SpeciesItem.cpp b/sigmod/SpeciesItem.cpp new file mode 100644 index 00000000..4cc27088 --- /dev/null +++ b/sigmod/SpeciesItem.cpp @@ -0,0 +1,108 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "SpeciesItem.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Species.h" + +Pokemod::SpeciesItem::SpeciesItem(const SpeciesItem& item) : + Object(item.parent(), item.id()) +{ + *this = item; +} + +Pokemod::SpeciesItem::SpeciesItem(const Species* parent, const int id) : + Object(parent, id), + m_item(INT_MAX), + m_weight(1) +{ +} + +Pokemod::SpeciesItem::SpeciesItem(const SpeciesItem& item, const Species* parent, const int id) : + Object(parent, id) +{ + *this = item; +} + +Pokemod::SpeciesItem::SpeciesItem(const QDomElement& xml, const Species* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::SpeciesItem::validate() +{ + TEST_BEGIN(); + TEST(setItem, item); + TEST(setWeight, weight); + TEST_END(); +} + +void Pokemod::SpeciesItem::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(item); + LOAD(weight); +} + +QDomElement Pokemod::SpeciesItem::save() const +{ + SAVE_CREATE(); + SAVE(item); + SAVE(weight); + return xml; +} + +void Pokemod::SpeciesItem::setItem(const int item) +{ + if (qobject_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) + emit(error(bounds("item"))); + else + CHECK(item); +} + +void Pokemod::SpeciesItem::setWeight(const int weight) +{ + if (!weight) + emit(error(bounds("weight"))); + else + CHECK(weight); +} + +int Pokemod::SpeciesItem::item() const +{ + return m_item; +} + +int Pokemod::SpeciesItem::weight() const +{ + return m_weight; +} + +Pokemod::SpeciesItem& Pokemod::SpeciesItem::operator=(const SpeciesItem& rhs) +{ + if (this == &rhs) + return *this; + COPY(item); + COPY(weight); + return *this; +} diff --git a/sigmod/SpeciesItem.h b/sigmod/SpeciesItem.h new file mode 100644 index 00000000..93f4fc3c --- /dev/null +++ b/sigmod/SpeciesItem.h @@ -0,0 +1,57 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SPECIESITEM__ +#define __POKEMOD_SPECIESITEM__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Species; + +class POKEMOD_EXPORT SpeciesItem : public Object +{ + Q_OBJECT + + public: + SpeciesItem(const SpeciesItem& item); + SpeciesItem(const Species* parent, const int id); + SpeciesItem(const SpeciesItem& item, const Species* parent, const int id); + SpeciesItem(const QDomElement& xml, const Species* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setItem(const int item); + void setWeight(const int weight); + + int item() const; + int weight() const; + + SpeciesItem& operator=(const SpeciesItem& rhs); + private: + int m_item; + int m_weight; +}; +} + +#endif diff --git a/sigmod/SpeciesMove.cpp b/sigmod/SpeciesMove.cpp new file mode 100644 index 00000000..da1ae662 --- /dev/null +++ b/sigmod/SpeciesMove.cpp @@ -0,0 +1,127 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "SpeciesMove.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Rules.h" +#include "Species.h" + +Pokemod::SpeciesMove::SpeciesMove(const SpeciesMove& move) : + Object(move.parent(), move.id()) +{ + *this = move; +} + +Pokemod::SpeciesMove::SpeciesMove(const Species* parent, const int id) : + Object(parent, id), + m_move(INT_MAX), + m_level(0), + m_wild(0) +{ +} + +Pokemod::SpeciesMove::SpeciesMove(const SpeciesMove& move, const Species* parent, const int id) : + Object(parent, id) +{ + *this = move; +} + +Pokemod::SpeciesMove::SpeciesMove(const QDomElement& xml, const Species* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::SpeciesMove::validate() +{ + TEST_BEGIN(); + TEST(setMove, move); + TEST(setLevel, level); + TEST(setWild, wild); + TEST_END(); +} + +void Pokemod::SpeciesMove::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(move); + LOAD(level); + LOAD(wild); +} + +QDomElement Pokemod::SpeciesMove::save() const +{ + SAVE_CREATE(); + SAVE(move); + SAVE(level); + SAVE(wild); + return xml; +} + +void Pokemod::SpeciesMove::setMove(const int move) +{ + if (qobject_cast<const Pokemod*>(pokemod())->moveIndex(move) == INT_MAX) + emit(error(bounds("move"))); + else + CHECK(move); +} + +void Pokemod::SpeciesMove::setLevel(const int level) +{ + if (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= level) + emit(error(bounds("level"))); + else + CHECK(level); +} + +void Pokemod::SpeciesMove::setWild(const int wild) +{ + if (!wild || (qobject_cast<const Pokemod*>(pokemod())->rules()->maxLevel() <= wild)) + emit(error(bounds("wild"))); + else + CHECK(wild); +} + +int Pokemod::SpeciesMove::move() const +{ + return m_move; +} + +int Pokemod::SpeciesMove::level() const +{ + return m_level; +} + +int Pokemod::SpeciesMove::wild() const +{ + return m_wild; +} + +Pokemod::SpeciesMove& Pokemod::SpeciesMove::operator=(const SpeciesMove& rhs) +{ + if (this == &rhs) + return *this; + COPY(move); + COPY(level); + COPY(wild); + return *this; +} diff --git a/sigmod/SpeciesMove.h b/sigmod/SpeciesMove.h new file mode 100644 index 00000000..affc9530 --- /dev/null +++ b/sigmod/SpeciesMove.h @@ -0,0 +1,60 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SPECIESMOVE__ +#define __POKEMOD_SPECIESMOVE__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Species; + +class POKEMOD_EXPORT SpeciesMove : public Object +{ + Q_OBJECT + + public: + SpeciesMove(const SpeciesMove& move); + SpeciesMove(const Species* parent, const int id); + SpeciesMove(const SpeciesMove& move, const Species* parent, const int id); + SpeciesMove(const QDomElement& xml, const Species* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setMove(const int move); + void setLevel(const int level); + void setWild(const int wild); + + int move() const; + int level() const; + int wild() const; + + SpeciesMove& operator=(const SpeciesMove& rhs); + private: + int m_move; + int m_level; + int m_wild; +}; +} + +#endif diff --git a/sigmod/Sprite.cpp b/sigmod/Sprite.cpp new file mode 100644 index 00000000..2000bf86 --- /dev/null +++ b/sigmod/Sprite.cpp @@ -0,0 +1,106 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Sprite.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +Pokemod::Sprite::Sprite(const Sprite& sprite) : + Object(sprite.parent(), sprite.id()) +{ + *this = sprite; +} + +Pokemod::Sprite::Sprite(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_sprite() +{ +} + +Pokemod::Sprite::Sprite(const Sprite& sprite, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = sprite; +} + +Pokemod::Sprite::Sprite(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::Sprite::~Sprite() +{ +} + +void Pokemod::Sprite::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::Sprite::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(sprite); +} + +QDomElement Pokemod::Sprite::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(sprite); + return xml; +} + +void Pokemod::Sprite::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Sprite::setSprite(const QImage& sprite) +{ + m_sprite = sprite; + emit(changed()); +} + +QString Pokemod::Sprite::name() const +{ + return m_name; +} + +QImage Pokemod::Sprite::sprite() const +{ + return m_sprite; +} + +Pokemod::Sprite& Pokemod::Sprite::operator=(const Sprite& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(sprite); + return *this; +} diff --git a/sigmod/Sprite.h b/sigmod/Sprite.h new file mode 100644 index 00000000..f23422a0 --- /dev/null +++ b/sigmod/Sprite.h @@ -0,0 +1,61 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_SPRITE__ +#define __POKEMOD_SPRITE__ + +// Pokemod includes +#include "Object.h" + +// Qt includes +#include <QtGui/QImage> + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Sprite : public Object +{ + Q_OBJECT + + public: + Sprite(const Sprite& sprite); + Sprite(const Pokemod* parent, const int id); + Sprite(const Sprite& sprite, const Pokemod* parent, const int id); + Sprite(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~Sprite(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setSprite(const QImage& sprite); + + QString name() const; + QImage sprite() const; + + Sprite& operator=(const Sprite& rhs); + private: + QString m_name; + QImage m_sprite; +}; +} + +#endif diff --git a/sigmod/Status.cpp b/sigmod/Status.cpp new file mode 100644 index 00000000..04702d48 --- /dev/null +++ b/sigmod/Status.cpp @@ -0,0 +1,120 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Status.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Script.h" + +Pokemod::Status::Status(const Status& status) : + Object(status.parent(), status.id()) +{ + *this = status; +} + +Pokemod::Status::Status(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_battleScript("", ""), + m_worldScript("", "") +{ +} + +Pokemod::Status::Status(const Status& status, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = status; +} + +Pokemod::Status::Status(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::Status::~Status() +{ +} + +void Pokemod::Status::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::Status::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(battleScript); + LOAD(worldScript); +} + +QDomElement Pokemod::Status::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(battleScript); + SAVE(worldScript); + return xml; +} + +void Pokemod::Status::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Status::setBattleScript(const Script& battleScript) +{ + CHECK(battleScript); +} + +void Pokemod::Status::setWorldScript(const Script& worldScript) +{ + CHECK(worldScript); +} + +QString Pokemod::Status::name() const +{ + return m_name; +} + +Pokemod::Script Pokemod::Status::battleScript() const +{ + return m_battleScript; +} + +Pokemod::Script Pokemod::Status::worldScript() const +{ + return m_worldScript; +} + +Pokemod::Status& Pokemod::Status::operator=(const Status& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(battleScript); + COPY(worldScript); + return *this; +} diff --git a/sigmod/Status.h b/sigmod/Status.h new file mode 100644 index 00000000..af801957 --- /dev/null +++ b/sigmod/Status.h @@ -0,0 +1,62 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_STATUS__ +#define __POKEMOD_STATUS__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Status : public Object +{ + Q_OBJECT + + public: + Status(const Status& status); + Status(const Pokemod* parent, const int id); + Status(const Status& status, const Pokemod* parent, const int id); + Status(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~Status(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setBattleScript(const Script& battleScript); + void setWorldScript(const Script& worldScript); + + QString name() const; + Script battleScript() const; + Script worldScript() const; + + Status& operator=(const Status& rhs); + private: + QString m_name; + Script m_battleScript; + Script m_worldScript; +}; +} + +#endif diff --git a/sigmod/Store.cpp b/sigmod/Store.cpp new file mode 100644 index 00000000..977bf6a9 --- /dev/null +++ b/sigmod/Store.cpp @@ -0,0 +1,118 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Store.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +Pokemod::Store::Store(const Store& store) : + Object(store.parent(), store.id()) +{ + *this = store; +} + +Pokemod::Store::Store(const Pokemod* parent, const int id) : + Object(parent, id), + m_name("") +{ +} + +Pokemod::Store::Store(const Store& store, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = store; +} + +Pokemod::Store::Store(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Store::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + if (m_item.size()) + TEST_LIST(setItem, item); + else + emit(error("No items in the store")); + TEST_END(); +} + +void Pokemod::Store::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD_LIST(item); +} + +QDomElement Pokemod::Store::save() const +{ + SAVE_CREATE(); + SAVE_LIST(item); + return xml; +} + +void Pokemod::Store::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Store::setItem(const int item, const bool state) +{ + if (qobject_cast<const Pokemod*>(pokemod())->itemIndex(item) == INT_MAX) + emit(error(bounds("item"))); + else if (state && !m_item.contains(item)) + { + m_item.append(item); + emit(changed()); + } + else if (m_item.contains(item)) + { + m_item.removeAll(item); + emit(changed()); + } +} + +QString Pokemod::Store::name() const +{ + return m_name; +} + +bool Pokemod::Store::item(const int item) const +{ + return m_item.contains(item); +} + +QList<int> Pokemod::Store::items() const +{ + return m_item; +} + +Pokemod::Store& Pokemod::Store::operator=(const Store& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(item); + return *this; +} diff --git a/sigmod/Store.h b/sigmod/Store.h new file mode 100644 index 00000000..48ae4342 --- /dev/null +++ b/sigmod/Store.h @@ -0,0 +1,61 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_STORE__ +#define __POKEMOD_STORE__ + +// Pokemod includes +#include "Object.h" + +// Qt includes +#include <QtCore/QList> + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Store : public Object +{ + Q_OBJECT + + public: + Store(const Store& store); + Store(const Pokemod* parent, const int id); + Store(const Store& store, const Pokemod* parent, const int id); + Store(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setItem(const int item, const bool state); + + QString name() const; + bool item(const int item) const; + QList<int> items() const; + + Store& operator=(const Store& rhs); + private: + QString m_name; + QList<int> m_item; +}; +} + +#endif diff --git a/sigmod/TODO b/sigmod/TODO new file mode 100644 index 00000000..f9bde618 --- /dev/null +++ b/sigmod/TODO @@ -0,0 +1,3 @@ +Properly inline methods (http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.9)
+
+Species::validate() gives a (possible) noreturn option (???)
diff --git a/sigmod/Tile.cpp b/sigmod/Tile.cpp new file mode 100644 index 00000000..c58f7e01 --- /dev/null +++ b/sigmod/Tile.cpp @@ -0,0 +1,139 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Tile.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Sprite.h" + +Pokemod::Tile::Tile(const Tile& tile) : + Object(tile.parent(), tile.id()) +{ + *this = tile; +} + +Pokemod::Tile::Tile(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_sprite(-1), + m_from(D_End), + m_script("", "") +{ + for (int i = 0; i < m_from.size(); ++i) + m_from[i] = false; +} + +Pokemod::Tile::Tile(const Tile& tile, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = tile; +} + +Pokemod::Tile::Tile(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Tile::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setSprite, sprite); + TEST_END(); +} + +void Pokemod::Tile::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(sprite); + LOAD_ARRAY(from); + LOAD(script); +} + +QDomElement Pokemod::Tile::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(sprite); + SAVE_ARRAY(from); + SAVE(script); + return xml; +} + +void Pokemod::Tile::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Tile::setSprite(const int sprite) +{ + if (qobject_cast<const Pokemod*>(pokemod())->spriteIndex(sprite) == INT_MAX) + emit(error(bounds("sprite"))); + // FIXME: remove if doing collaging + else if (qobject_cast<const Pokemod*>(pokemod())->spriteById(sprite)->sprite().size() != QSize(64, 64)) + emit(error("Sprite is the wrong dimensions")); + else + CHECK(sprite); +} + +void Pokemod::Tile::setFrom(const Direction direction, const bool state) +{ + CHECK_ARRAY(from[direction], state); +} + +void Pokemod::Tile::setScript(const Script& script) +{ + CHECK(script); +} + +QString Pokemod::Tile::name() const +{ + return m_name; +} + +int Pokemod::Tile::sprite() const +{ + return m_sprite; +} + +bool Pokemod::Tile::from(const Direction direction) const +{ + return m_from[direction]; +} + +Pokemod::Script Pokemod::Tile::script() const +{ + return m_script; +} + +Pokemod::Tile& Pokemod::Tile::operator=(const Tile& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(sprite); + COPY(from); + COPY(script); + return *this; +} diff --git a/sigmod/Tile.h b/sigmod/Tile.h new file mode 100644 index 00000000..0cba7563 --- /dev/null +++ b/sigmod/Tile.h @@ -0,0 +1,64 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_TILE__ +#define __POKEMOD_TILE__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Tile : public Object +{ + Q_OBJECT + + public: + Tile(const Tile& tile); + Tile(const Pokemod* parent, const int id); + Tile(const Tile& tile, const Pokemod* parent, const int id); + Tile(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setSprite(const int sprite); + void setFrom(const Direction direction, const bool state); + void setScript(const Script& script); + + QString name() const; + int sprite() const; + bool from(const Direction direction) const; + Script script() const; + + Tile& operator=(const Tile& rhs); + private: + QString m_name; + int m_sprite; + QVarLengthArray<bool, D_End> m_from; + Script m_script; +}; +} + +#endif diff --git a/sigmod/Time.cpp b/sigmod/Time.cpp new file mode 100644 index 00000000..e1ced90a --- /dev/null +++ b/sigmod/Time.cpp @@ -0,0 +1,123 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Time.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +Pokemod::Time::Time(const Time& time) : + Object(time.parent(), time.id()) +{ + *this = time; +} + +Pokemod::Time::Time(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_hour(0), + m_minute(0) +{ +} + +Pokemod::Time::Time(const Time& time, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = time; +} + +Pokemod::Time::Time(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Time::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setHour, hour); + TEST(setMinute, minute); + TEST_END(); +} + +void Pokemod::Time::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(hour); + LOAD(minute); +} + +QDomElement Pokemod::Time::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(hour); + SAVE(minute); + return xml; +} + +void Pokemod::Time::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Time::setHour(const int hour) +{ + if (24 <= hour) + emit(error(bounds("hour"))); + else + CHECK(hour); +} + +void Pokemod::Time::setMinute(const int minute) +{ + if (60 <= minute) + emit(error(bounds("minute"))); + else + CHECK(minute); +} + +QString Pokemod::Time::name() const +{ + return m_name; +} + +int Pokemod::Time::hour() const +{ + return m_hour; +} + +int Pokemod::Time::minute() const +{ + return m_minute; +} + +Pokemod::Time& Pokemod::Time::operator=(const Time& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(hour); + COPY(minute); + return *this; +} diff --git a/sigmod/Time.h b/sigmod/Time.h new file mode 100644 index 00000000..9799f328 --- /dev/null +++ b/sigmod/Time.h @@ -0,0 +1,60 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_TIME__ +#define __POKEMOD_TIME__ + +// Pokemod includes +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Time : public Object +{ + Q_OBJECT + + public: + Time(const Time& time); + Time(const Pokemod* parent, const int id); + Time(const Time& time, const Pokemod* parent, const int id); + Time(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setHour(const int hour); + void setMinute(const int minutes); + + QString name() const; + int hour() const; + int minute() const; + + Time& operator=(const Time& rhs); + private: + QString m_name; + int m_hour; + int m_minute; +}; +} + +#endif diff --git a/sigmod/Trainer.cpp b/sigmod/Trainer.cpp new file mode 100644 index 00000000..0c80fc57 --- /dev/null +++ b/sigmod/Trainer.cpp @@ -0,0 +1,209 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Trainer.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +const QStringList Pokemod::Trainer::IntelligenceStr = QStringList() << "Ignorant" << "Remember" << "Cheating"; + +Pokemod::Trainer::Trainer(const Trainer& trainer) : + Object(trainer.parent(), trainer.id()) +{ + *this = trainer; +} + +Pokemod::Trainer::Trainer(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_moneyFactor(0), + m_skin(-1), + m_depth(0), + m_teamIntel(Remember), + m_moveIntel(Remember), + m_itemIntel(Remember), + m_abilityIntel(Remember), + m_statIntel(Remember) +{ +} + +Pokemod::Trainer::Trainer(const Trainer& trainer, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = trainer; +} + +Pokemod::Trainer::Trainer(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Trainer::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST(setMoneyFactor, moneyFactor); + TEST(setSkin, skin); + TEST_END(); +} + +void Pokemod::Trainer::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(moneyFactor); + LOAD(skin); + LOAD(depth); + LOAD(teamIntel); + LOAD(moveIntel); + LOAD(itemIntel); + LOAD(abilityIntel); + LOAD(statIntel); +} + +QDomElement Pokemod::Trainer::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(moneyFactor); + SAVE(skin); + SAVE(depth); + SAVE(teamIntel); + SAVE(moveIntel); + SAVE(itemIntel); + SAVE(abilityIntel); + SAVE(statIntel); + return xml; +} + +void Pokemod::Trainer::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Trainer::setMoneyFactor(const int moneyFactor) +{ + if (moneyFactor < 0) + emit(error(bounds("moneyFactor"))); + else + CHECK(moneyFactor); +} + +void Pokemod::Trainer::setSkin(const int skin) +{ + if (qobject_cast<const Pokemod*>(pokemod())->skinIndex(skin) == INT_MAX) + emit(error(bounds("skin"))); + else + CHECK(skin); +} + +void Pokemod::Trainer::setDepth(const int depth) +{ + CHECK(depth); +} + +void Pokemod::Trainer::setTeamIntel(const Intelligence teamIntel) +{ + CHECK(teamIntel); +} + +void Pokemod::Trainer::setMoveIntel(const Intelligence moveIntel) +{ + CHECK(moveIntel); +} + +void Pokemod::Trainer::setItemIntel(const Intelligence itemIntel) +{ + CHECK(itemIntel); +} + +void Pokemod::Trainer::setAbilityIntel(const Intelligence abilityIntel) +{ + CHECK(abilityIntel); +} + +void Pokemod::Trainer::setStatIntel(const Intelligence statIntel) +{ + CHECK(statIntel); +} + +QString Pokemod::Trainer::name() const +{ + return m_name; +} + +int Pokemod::Trainer::moneyFactor() const +{ + return m_moneyFactor; +} + +int Pokemod::Trainer::skin() const +{ + return m_skin; +} + +int Pokemod::Trainer::depth() const +{ + return m_depth; +} + +Pokemod::Trainer::Intelligence Pokemod::Trainer::teamIntel() const +{ + return m_teamIntel; +} + +Pokemod::Trainer::Intelligence Pokemod::Trainer::moveIntel() const +{ + return m_moveIntel; +} + +Pokemod::Trainer::Intelligence Pokemod::Trainer::itemIntel() const +{ + return m_itemIntel; +} + +Pokemod::Trainer::Intelligence Pokemod::Trainer::abilityIntel() const +{ + return m_abilityIntel; +} + +Pokemod::Trainer::Intelligence Pokemod::Trainer::statIntel() const +{ + return m_statIntel; +} + +Pokemod::Trainer& Pokemod::Trainer::operator=(const Trainer& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(moneyFactor); + COPY(skin); + COPY(depth); + COPY(teamIntel); + COPY(moveIntel); + COPY(itemIntel); + COPY(abilityIntel); + COPY(statIntel); + return *this; +} diff --git a/sigmod/Trainer.h b/sigmod/Trainer.h new file mode 100644 index 00000000..8d4caa89 --- /dev/null +++ b/sigmod/Trainer.h @@ -0,0 +1,92 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_TRAINER__ +#define __POKEMOD_TRAINER__ + +// Pokemod includes +#include "Object.h" + +// Qt includes +#include <QtCore/QStringList> + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Trainer : public Object +{ + Q_OBJECT + Q_ENUMS(Intelligence) + + public: + enum Intelligence + { + Ignorant = 0, + Determine = 1, + Remember = 2, + Cheating = 3 + }; + static const QStringList IntelligenceStr; + + Trainer(const Trainer& trainer); + Trainer(const Pokemod* parent, const int id); + Trainer(const Trainer& trainer, const Pokemod* parent, const int id); + Trainer(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setMoneyFactor(const int moneyFactor); + void setSkin(const int skin); + void setDepth(const int depth); + void setTeamIntel(const Intelligence teamIntel); + void setMoveIntel(const Intelligence moveIntel); + void setItemIntel(const Intelligence itemIntel); + void setAbilityIntel(const Intelligence abilityIntel); + void setStatIntel(const Intelligence statIntel); + + QString name() const; + int moneyFactor() const; + int skin() const; + int depth() const; + Intelligence teamIntel() const; + Intelligence moveIntel() const; + Intelligence itemIntel() const; + Intelligence abilityIntel() const; + Intelligence statIntel() const; + + Trainer& operator=(const Trainer& rhs); + private: + QString m_name; + int m_moneyFactor; + int m_skin; + int m_depth; + Intelligence m_teamIntel; + Intelligence m_moveIntel; + Intelligence m_itemIntel; + Intelligence m_abilityIntel; + Intelligence m_statIntel; +}; +} +Q_DECLARE_METATYPE(Pokemod::Trainer::Intelligence) + +#endif diff --git a/sigmod/Type.cpp b/sigmod/Type.cpp new file mode 100644 index 00000000..2eb9202a --- /dev/null +++ b/sigmod/Type.cpp @@ -0,0 +1,104 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Type.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" + +Pokemod::Type::Type(const Type& type) : + Object(type.parent(), type.id()) +{ + *this = type; +} + +Pokemod::Type::Type(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_stab(1, 1) +{ +} + +Pokemod::Type::Type(const Type& type, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = type; +} + +Pokemod::Type::Type(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +void Pokemod::Type::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::Type::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(stab); +} + +QDomElement Pokemod::Type::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(stab); + return xml; +} + +void Pokemod::Type::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Type::setStab(const Fraction& stab) +{ + if (stab < 1) + emit(error(bounds("stab"))); + else + CHECK(stab); +} + +QString Pokemod::Type::name() const +{ + return m_name; +} + +Pokemod::Fraction Pokemod::Type::stab() const +{ + return m_stab; +} + +Pokemod::Type& Pokemod::Type::operator=(const Type& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(stab); + return *this; +} diff --git a/sigmod/Type.h b/sigmod/Type.h new file mode 100644 index 00000000..374537f6 --- /dev/null +++ b/sigmod/Type.h @@ -0,0 +1,58 @@ +/* + * Copyright 2007-2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_TYPE__ +#define __POKEMOD_TYPE__ + +// Pokemod includes +#include "Fraction.h" +#include "Object.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Type : public Object +{ + Q_OBJECT + + public: + Type(const Type& type); + Type(const Pokemod* parent, const int id); + Type(const Type& type, const Pokemod* parent, const int id); + Type(const QDomElement& xml, const Pokemod* parent, const int id = -1); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setStab(const Fraction& stab); + + QString name() const; + Fraction stab() const; + + Type& operator=(const Type& rhs); + private: + QString m_name; + Fraction m_stab; +}; +} + +#endif diff --git a/sigmod/Weather.cpp b/sigmod/Weather.cpp new file mode 100644 index 00000000..05d70d1c --- /dev/null +++ b/sigmod/Weather.cpp @@ -0,0 +1,106 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "Weather.h" + +// Pokemod includes +#include "Macros.h" +#include "Pokemod.h" +#include "Script.h" + +Pokemod::Weather::Weather(const Weather& weather) : + Object(weather.parent(), weather.id()) +{ + *this = weather; +} + +Pokemod::Weather::Weather(const Pokemod* parent, const int id) : + Object(parent, id), + m_name(""), + m_script("", "") +{ +} + +Pokemod::Weather::Weather(const Weather& weather, const Pokemod* parent, const int id) : + Object(parent, id) +{ + *this = weather; +} + +Pokemod::Weather::Weather(const QDomElement& xml, const Pokemod* parent, const int id) : + Object(parent, id) +{ + LOAD_ID(); + load(xml); +} + +Pokemod::Weather::~Weather() +{ +} + +void Pokemod::Weather::validate() +{ + TEST_BEGIN(); + if (m_name.isEmpty()) + emit(error("Name is empty")); + TEST_END(); +} + +void Pokemod::Weather::load(const QDomElement& xml) +{ + LOAD_BEGIN(); + LOAD(name); + LOAD(script); +} + +QDomElement Pokemod::Weather::save() const +{ + SAVE_CREATE(); + SAVE(name); + SAVE(script); + return xml; +} + +void Pokemod::Weather::setName(const QString& name) +{ + CHECK(name); +} + +void Pokemod::Weather::setScript(const Script& script) +{ + CHECK(script); +} + +QString Pokemod::Weather::name() const +{ + return m_name; +} + +Pokemod::Script Pokemod::Weather::script() const +{ + return m_script; +} + +Pokemod::Weather& Pokemod::Weather::operator=(const Weather& rhs) +{ + if (this == &rhs) + return *this; + COPY(name); + COPY(script); + return *this; +} diff --git a/sigmod/Weather.h b/sigmod/Weather.h new file mode 100644 index 00000000..cd9fa874 --- /dev/null +++ b/sigmod/Weather.h @@ -0,0 +1,59 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef __POKEMOD_WEATHER__ +#define __POKEMOD_WEATHER__ + +// Pokemod includes +#include "Object.h" +#include "Script.h" + +namespace Pokemod +{ +// Forward declarations +class Pokemod; + +class POKEMOD_EXPORT Weather : public Object +{ + Q_OBJECT + + public: + Weather(const Weather& weather); + Weather(const Pokemod* parent, const int id); + Weather(const Weather& weather, const Pokemod* parent, const int id); + Weather(const QDomElement& xml, const Pokemod* parent, const int id = -1); + ~Weather(); + + void validate(); + + void load(const QDomElement& xml); + QDomElement save() const; + + void setName(const QString& name); + void setScript(const Script& script); + + QString name() const; + Script script() const; + + Weather& operator=(const Weather& rhs); + private: + QString m_name; + Script m_script; +}; +} + +#endif |