diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-03-31 01:17:59 +0000 |
| commit | 9a65bc6bb7c8da1dfa5b101579e52845c75848ef (patch) | |
| tree | 258900f882a6998ac6fa525bd247e302028a8911 | |
| parent | 8e1ec2aec50999bae30625303f2c96e5b3b7f318 (diff) | |
| download | sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.gz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.tar.xz sigen-9a65bc6bb7c8da1dfa5b101579e52845c75848ef.zip | |
[FIX] Member variables now use m_ prefix
[FIX] Lots of minor fixes
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@95 6ecfd1a5-f3ed-3746-8530-beee90d26b22
97 files changed, 8321 insertions, 9083 deletions
@@ -1,4 +1,12 @@ ----------------- +Rev: 95 +Date: 30 March 2008 +User: MathStuf +----------------- +[FIX] Member variables now use m_ prefix +[FIX] Minor fixes + +----------------- Rev: 94 Date: 9 March 2008 User: MathStuf diff --git a/general/Audio.cpp b/general/Audio.cpp index 034de04d..46f2853b 100644 --- a/general/Audio.cpp +++ b/general/Audio.cpp @@ -1,25 +1,24 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Audio.cpp -// Purpose: Cache for sound effects -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri Jan 18 21:34:16 2008 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Qt includes +#include <QMutableListIterator> + +// Header include #include "Audio.h" void Audio::playSFX(const QString& url) throw(OpenException) @@ -29,28 +28,28 @@ void Audio::playSFX(const QString& url) throw(OpenException) if (sfx->state() == Phonon::ErrorState) throw(OpenException("Audio", url)); sfx->play(); - curPlay.append(sfx); + m_curPlay.append(sfx); } void Audio::playMusic(const QString& url) throw(OpenException) { - if (!started) + if (!m_started) start(); - musicUrl = url; - if (music.state() == Phonon::PlayingState) - music.seek(music.totalTime() - 1000); + m_musicUrl = url; + if (m_music.state() == Phonon::PlayingState) + m_music.seek(m_music.totalTime() - 1000); else { - music.setCurrentSource(url); - if (music.state() == Phonon::ErrorState) + m_music.setCurrentSource(url); + if (m_music.state() == Phonon::ErrorState) throw(OpenException("Audio", url)); - music.play(); + m_music.play(); } } void Audio::prune() { - for (QMutableListIterator<Phonon::MediaObject*> i(curPlay); i.hasNext(); i.next()) + for (QMutableListIterator<Phonon::MediaObject*> i(m_curPlay); i.hasNext(); i.next()) { if (i.value()->state() == Phonon::StoppedState) { @@ -62,7 +61,7 @@ void Audio::prune() void Audio::clear() { - for (QMutableListIterator<Phonon::MediaObject*> i(curPlay); i.hasNext(); i.next()) + for (QMutableListIterator<Phonon::MediaObject*> i(m_curPlay); i.hasNext(); i.next()) { if (i.value()->state() == Phonon::PlayingState) i.value()->stop(); diff --git a/general/Audio.h b/general/Audio.h index 9c841af0..aef1cb63 100644 --- a/general/Audio.h +++ b/general/Audio.h @@ -1,35 +1,34 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Audio.h -// Purpose: Sound effect handling -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri Jan 18 15:29:22 2008 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __AUDIO__ #define __AUDIO__ +// KDE includes #include <phonon/audiooutput.h> -//#include <Phonon/AudioOutput> #include <phonon/mediaobject.h> -//#include <Phonon/MediaObject> +// QT includes +// #include <Phonon/AudioOutput> +// #include <Phonon/MediaObject> +#include <QList> #include <QObject> +// General includes #include "Exception.h" class Audio : public QObject @@ -37,12 +36,12 @@ class Audio : public QObject Q_OBJECT public: - Audio() : - output(Phonon::MusicCategory), - started(false) + inline Audio() : + m_output(Phonon::MusicCategory), + m_started(false) { } - ~Audio() + inline ~Audio() { clear(); } @@ -53,31 +52,31 @@ class Audio : public QObject void prune(); void clear(); - double getVolume() + inline double volume() { - return output.volume(); + return m_output.volume(); } - void setVolume(const double v) + inline void setVolume(const double volume) { - output.setVolume(v); + m_output.setVolume(volume); } private: - void start() + inline void start() { - if (!started) - connect(&music, SIGNAL(aboutToFinish()), this, SLOT(loopMusic())); + if (!m_started) + connect(&m_music, SIGNAL(aboutToFinish()), this, SLOT(loopMusic())); } private slots: - void loopMusic() + inline void loopMusic() { - music.enqueue(musicUrl); + m_music.enqueue(m_musicUrl); } private: - QList<Phonon::MediaObject*> curPlay; - Phonon::MediaObject music; - QString musicUrl; - Phonon::AudioOutput output; - bool started; + QList<Phonon::MediaObject*> m_curPlay; + Phonon::MediaObject m_music; + QString m_musicUrl; + Phonon::AudioOutput m_output; + bool m_started; }; #endif diff --git a/general/BugCatcher.cpp b/general/BugCatcher.cpp index eff96816..e83dc87c 100644 --- a/general/BugCatcher.cpp +++ b/general/BugCatcher.cpp @@ -1,25 +1,21 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/BugCatcher.cpp -// Purpose: Exceptions get sent here -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Jan 22 14:47:50 2008 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 "BugCatcher.h" -KAboutData* BugCatcher::about = NULL; +KAboutData* BugCatcher::m_aboutData = NULL; diff --git a/general/BugCatcher.h b/general/BugCatcher.h index bfae6290..8d1bc1e0 100644 --- a/general/BugCatcher.h +++ b/general/BugCatcher.h @@ -1,55 +1,52 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/BugCatcher.h -// Purpose: Exceptions get sent here -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Mon Jan 21 15:57:40 2008 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __BUGCATCHER__ #define __BUGCATCHER__ -#include <kaboutdata.h> +// KDE includes +class KAboutData; #include <kbugreport.h> #include <kmessagebox.h> +// General includes #include "Exception.h" class BugCatcher { public: - static void setAbout(KAboutData* data) + static void setAbout(KAboutData* aboutData) { - about = data; + m_aboutData = aboutData; } static void deleteAbout() { - about = NULL; + m_aboutData = NULL; } - static void report(const Exception& e) + static void report(const Exception& exception) { - if (!about) + if (!m_aboutData) return; - KBugReport bug(NULL, true, about); - if (KMessageBox::questionYesNo(&bug, "Missed an error catching spot. Please email me (MathStuf@gmail.com) with the error and \"PokeModr - error\" as the subject.", e.getMsg()) == KMessageBox::Yes) + KBugReport bug(NULL, true, m_aboutData); + if (KMessageBox::questionYesNo(&bug, "Missed an error catching spot. Please email me (MathStuf@gmail.com) with the error and \"PokeModr - error\" as the subject.", exception.getMsg()) == KMessageBox::Yes) bug.exec(); } private: - static KAboutData* about; + static KAboutData* m_aboutData; }; #endif diff --git a/general/Exception.h b/general/Exception.h index ea8b314a..c5eacd4e 100644 --- a/general/Exception.h +++ b/general/Exception.h @@ -1,53 +1,49 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Exception.h -// Purpose: Define exceptions used throughout PokéGen -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Jan 16 13:13:13 2008 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __EXCEPTIONS__ #define __EXCEPTIONS__ +// Qt includes #include <QString> class Exception { public: - Exception(const QString& c, const QString e) : - cls(c), - error(e) + Exception(const QString& className, const QString error) : + m_className(className), + m_error(error) { } QString getMsg() const { - return QString("%1: %2").arg(cls).arg(error); + return QString("%1: %2").arg(m_className).arg(m_error); } private: - const QString cls; - const QString error; + const QString m_className; + const QString m_error; }; class UnusedException : public Exception { public: - UnusedException(const QString& c, const QString& var) : - Exception(c, QString("setting unused %1").arg(var)) + UnusedException(const QString& className, const QString& variable) : + Exception(className, QString("setting unused %1").arg(variable)) { } }; @@ -55,8 +51,8 @@ class UnusedException : public Exception class BoundsException : public Exception { public: - BoundsException(const QString& c, const QString& var) : - Exception(c, QString("%1 out-of-bounds").arg(var)) + BoundsException(const QString& className, const QString& variable) : + Exception(className, QString("%1 out-of-bounds").arg(variable)) { } }; @@ -64,8 +60,8 @@ class BoundsException : public Exception class IndexException : public BoundsException { public: - IndexException(const QString& c) : - BoundsException(c, "index") + IndexException(const QString& className) : + BoundsException(className, "index") { } }; @@ -73,8 +69,8 @@ class IndexException : public BoundsException class ReplaceException : public Exception { public: - ReplaceException(const QString& c, const QString& f) : - Exception(c, QString("unable to replace %1").arg(f)) + ReplaceException(const QString& className, const QString& fileName) : + Exception(className, QString("unable to replace %1").arg(fileName)) { } }; @@ -82,8 +78,8 @@ class ReplaceException : public Exception class SaveException : public Exception { public: - SaveException(const QString& c, const QString& f) : - Exception(c, QString("unable to save %1").arg(f)) + SaveException(const QString& className, const QString& fileName) : + Exception(className, QString("unable to save %1").arg(fileName)) { } }; @@ -91,8 +87,8 @@ class SaveException : public Exception class OpenException : public Exception { public: - OpenException(const QString& c, const QString& f) : - Exception(c, QString("unable to open %1").arg(f)) + OpenException(const QString& className, const QString& fileName) : + Exception(className, QString("unable to open %1").arg(fileName)) { } }; @@ -100,8 +96,8 @@ class OpenException : public Exception class DirException : public Exception { public: - DirException(const QString& c, const QString& p) : - Exception(c, QString("unable to create path %1").arg(p)) + DirException(const QString& className, const QString& path) : + Exception(className, QString("unable to create path %1").arg(path)) { } }; @@ -109,8 +105,8 @@ class DirException : public Exception class InvalidException : public Exception { public: - InvalidException(const QString& c, const QString& f) : - Exception(c, QString("%1 is invalid").arg(f)) + InvalidException(const QString& className, const QString& fileName) : + Exception(className, QString("%1 is invalid").arg(fileName)) { } }; @@ -118,8 +114,8 @@ class InvalidException : public Exception class RemoveException : public Exception { public: - RemoveException(const QString& c, const QString& f) : - Exception(c, QString("unable to remove %1").arg(f)) + RemoveException(const QString& className, const QString& fileName) : + Exception(className, QString("unable to remove %1").arg(fileName)) { } }; diff --git a/general/Flag.cpp b/general/Flag.cpp index f2002f5a..cc8918b4 100644 --- a/general/Flag.cpp +++ b/general/Flag.cpp @@ -1,25 +1,21 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Flag.cpp -// Purpose: A class that handles flags -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sun Mar 18 15:25:16 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 "Flag.h" const QStringList Flag::ValueStr = QStringList() << "Off" << "On" << "Ignore"; diff --git a/general/Flag.h b/general/Flag.h index 1b7d5857..ecf567f3 100644 --- a/general/Flag.h +++ b/general/Flag.h @@ -1,30 +1,29 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Flag.h -// Purpose: A class that handles flags -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 19:22 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __FLAG__ #define __FLAG__ +// Qt includes #include <QStringList> +// General includes +#include "Exception.h" + class Flag { public: @@ -37,39 +36,39 @@ class Flag }; static const QStringList ValueStr; - Flag(const int f = 0, const int s = 0) : - flag(f) + inline Flag(const int flag = 0, const int status = 0) : + m_flag(flag) { - setStatus(s); + setStatus(status); } - void set(const int f, const int s) + inline void set(const int flag, const int status) { - setFlag(f); - setStatus(s); + setFlag(flag); + setStatus(status); } - void setFlag(const int f) + inline void setFlag(const int flag) { - flag = f; + m_flag = flag; } - void setStatus(const int s) + void setStatus(const int status) throw(BoundsException) { - if (End <= s) - throw("Flag: status out-of-bounds"); - status = s; + if (End <= status) + throw(BoundsException("Flag", "status")); + m_status = status; } - int getFlag() const + inline int flag() const { - return flag; + return m_flag; } - int getStatus() const + inline int status() const { - return status; + return m_status; } private: - int flag; - int status; + int m_flag; + int m_status; }; #endif diff --git a/general/Frac.cpp b/general/Frac.cpp index 317fdc53..36d0f591 100644 --- a/general/Frac.cpp +++ b/general/Frac.cpp @@ -1,60 +1,53 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Frac.cpp -// Purpose: A class to make handling fractions easier -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sun Mar 18 15:25:16 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 "Frac.h" -void Frac::set(const int n, const int d) throw(Exception) +void Frac::set(const int numerator, const int denominator) throw(Exception) { - if (((type == Improper) || ((n <= d) && (type == Proper)) || ((d <= n) && (type == Over1))) && (0 < d)) + if (((m_type == Improper) || ((numerator <= denominator) && (m_type == Proper)) || ((denominator <= numerator) && (m_type == Over1))) && (0 < numerator)) { - num = n; - denom = d; + m_numerator = numerator; + m_denominator = denominator; } else throw(Exception("Frac", "values conflict with type")); } -void Frac::set(const int n, const int d, const int t) throw(Exception) +void Frac::set(const int numerator, const int demoninator, const int type) throw(Exception) { - setType(t); - set(n, d); + setType(type); + set(numerator, demoninator); } -void Frac::setNum(const int n) throw(Exception) +void Frac::setType(const int type) throw(BoundsException) { - set(n, denom); -} - -void Frac::setDenom(const int d) throw(Exception) -{ - set(num, d); -} - -void Frac::setType(const int t) throw(BoundsException) -{ - if (t < End) + if (type < End) { - type = t; - set(1, 1); + m_type = type; + try + { + set(m_numerator, m_denominator); + } + catch (Exception& e) + { + set(1, 1); + } } else throw(BoundsException("Frac", "type")); @@ -62,10 +55,10 @@ void Frac::setType(const int t) throw(BoundsException) void Frac::reduce() { - int i = num; - int j = denom; + int i = m_numerator; + int j = m_denominator; while (i - j) (i > j) ? (i -= j) : (j -= i); - num /= i; - denom /= i; + m_numerator /= i; + m_denominator /= i; } diff --git a/general/Frac.h b/general/Frac.h index adf39b06..6a2a8f70 100644 --- a/general/Frac.h +++ b/general/Frac.h @@ -1,31 +1,29 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Frac.h -// Purpose: A class to make handling fractions easier -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sun Mar 18 15:25:16 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __FRAC__ #define __FRAC__ +// Qt includes +#include <QtGlobal> #include <QFile> #include <QString> +// General includes #include "Exception.h" class Frac @@ -34,49 +32,59 @@ class Frac enum { Proper = 0, - Improper = 1, - Over1 = 2, + Over1 = 1, + Improper = 2, End = 3 }; - Frac(const int t = Proper) + inline Frac(const int type = Proper) { - setType(t); + set(1, 1, type); } - Frac(const int n, const int d, const int t = Proper) throw(Exception) + inline Frac(const int numerator, const int denominator, const int type = Proper) throw(Exception) { - set(n, d, t); + set(numerator, denominator, type); } - void set(const int n, const int d) throw(Exception); - void set(const int n, const int d, const int t) throw(Exception); - void setNum(const int n) throw(Exception); - void setDenom(const int d) throw(Exception); - void setType(const int t) throw(BoundsException); + void set(const int numerator, const int denominator) throw(Exception); + void set(const int numerator, const int denominator, const int type) throw(Exception); + inline void setNumerator(const int numerator) throw(Exception) + { + set(numerator, m_denominator); + } + inline void setDenominator(const int denominator) throw(Exception) + { + set(m_numerator, denominator); + } + void setType(const int type) throw(BoundsException); - int getNum() const + inline int numerator() const { - return num; + return m_numerator; } - int getDenom() const + inline int denominator() const { - return denom; + return m_denominator; } - int getType() const + inline int type() const { - return type; + return m_type; } void reduce(); - operator double() const + inline operator double() const + { + return (double(m_numerator) / m_denominator); + } + inline Frac operator*(const Frac& rhs) const { - return (double(num) / denom); + return Frac(m_numerator * rhs.m_numerator, m_denominator * rhs.m_denominator, qMax(m_type, rhs.m_type)); } private: - int num; - int denom; - int type; + int m_numerator; + int m_denominator; + int m_type; }; #endif diff --git a/general/Hat.h b/general/Hat.h index 904f0cb9..ebb19e40 100644 --- a/general/Hat.h +++ b/general/Hat.h @@ -1,83 +1,93 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Hat.h -// Purpose: Class for easy random containers -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue May 29 2007 08:23:57 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __HAT__ #define __HAT__ +// Qt includes +#include <QtGlobal> #include <QDateTime> #include <QMap> -#include <QMutableMapIterator> -#include <QtGlobal> + +// General includes +#include "Exception.h" template<class T> class Hat { public: Hat() : - totalWeight(1) + m_count(0) { qsrand(QDateTime().toTime_t()); } T pick() const { - int choice = qrand() % totalWeight; - for (QMutableMapIterator<T, unsigned> i(objects); i.hasNext(); i.next()) + int choice = qrand() % m_count; + foreach (T key, m_objects.keys()) { - choice -= i.value(); + choice -= m_objects[key]; if (choice < 0) - return i.key(); + break; } + return key; } T take() { T chosen = pick(); - if (!(--objects[chosen])) - objects.erase(chosen); - --totalWeight; + if (!(--m_objects[chosen])) + m_objects.erase(chosen); + --m_count; return chosen; } - - void setCount(const T& key, const unsigned wt) + void setCount(const T& key, const unsigned weight) { - if (objects.find(key) != objects.end()) - totalWeight -= objects[key]; - objects[key] = wt; - totalWeight += wt; + if (m_objects.contains(key)) + m_count -= m_objects[key]; + m_objects[key] = weight; + m_count += weight; } - - unsigned getCount(const T& key) const + void add(const T& key, const unsigned weight) + { + m_objects[key] += weight; + m_count += weight; + } + unsigned count() const + { + return m_count; + } + unsigned count(const T& key) const + { + if (m_objects.contains(key)) + return m_objects[key]; + return 0; + } + double chance(const T& key) const { - if (objects.find(key) != objects.end()) - return objects[key]; - throw("Hat: key does not exist"); + return (double(count(key)) / m_count); } unsigned operator[](const T& key) const { - return getCount(key); + return count(key); } private: - QMap<T, unsigned> objects; - unsigned totalCount; + QMap<T, unsigned> m_objects; + unsigned m_count; }; #endif diff --git a/general/ImageCache.cpp b/general/ImageCache.cpp index a5ce28f3..22f09a03 100644 --- a/general/ImageCache.cpp +++ b/general/ImageCache.cpp @@ -1,36 +1,33 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/ImageCache.h -// Purpose: Cache for quick image loading -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Thu Jan 17 2008 13:42:44 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Qt includes #include <QFile> #include <QString> +// Header include #include "ImageCache.h" -KPixmapCache ImageCache::cache("pokegen"); +KPixmapCache ImageCache::m_cache("pokegen"); -QPixmap ImageCache::open(const QString& fname) throw(OpenException) +QPixmap ImageCache::open(const QString& fileName) throw(OpenException) { - if (!QFile::exists(fname)) - throw(OpenException("ImageCache", fname)); - QPixmap pm(cache.loadFromFile(fname)); + if (!QFile::exists(fileName)) + throw(OpenException("ImageCache", fileName)); + QPixmap pm(m_cache.loadFromFile(fileName)); return pm; } diff --git a/general/ImageCache.h b/general/ImageCache.h index e693dc1d..3f8b29c0 100644 --- a/general/ImageCache.h +++ b/general/ImageCache.h @@ -1,44 +1,42 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/ImageCache.h -// Purpose: Cache for quick image loading -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Thu Jan 17 2008 12:35:22 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __IMAGECACHE__ #define __IMAGECACHE__ +// KDE includes #include <kpixmapcache.h> +// Qt includes #include <QPixmap> +// General includes #include "Exception.h" class ImageCache { public: - static QPixmap open(const QString& fname) throw(OpenException); + static QPixmap open(const QString& fileName) throw(OpenException); static void clear() { - cache.discard(); + m_cache.discard(); } private: - static KPixmapCache cache; + static KPixmapCache m_cache; }; #endif diff --git a/general/Ini.cpp b/general/Ini.cpp index 269a832d..859dc59b 100644 --- a/general/Ini.cpp +++ b/general/Ini.cpp @@ -1,45 +1,42 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Ini.cpp -// Purpose: Define sections for data files -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri May 4 23:27:37 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QDir> #include <QStringList> #include <QTextStream> +// Header include #include "Ini.h" Ini::Ini() { } -Ini::Ini(const QString& fname) throw(Exception) +Ini::Ini(const QString& fileName) throw(Exception) { - load(fname); + load(fileName); } -void Ini::load(const QString& fname) throw(Exception) +void Ini::load(const QString& fileName) throw(Exception) { - QFile fin(fname); + QFile fin(fileName); if (!fin.exists()) - throw(OpenException("Ini", fname)); + throw(OpenException("Ini", fileName)); load(fin); fin.close(); } @@ -51,30 +48,30 @@ void Ini::load(QFile& fin) throw(InvalidException) QString field; QString value; int pos; - fields.clear(); + m_fields.clear(); while (!file.atEnd()) { pos = line.indexOf('='); - if (pos == -1) + if (pos == INT_MAX) throw(InvalidException("Ini", fin.fileName())); field = line.mid(0, pos - 1); value = line.mid(pos + 1, line.length() - pos); if (field.isEmpty()) throw(InvalidException("Ini", fin.fileName())); - fields[field] = value; + m_fields[field] = value; line = file.readLine(); } } -void Ini::save(const QString& fname) const throw(Exception) +void Ini::save(const QString& fileName) const throw(Exception) { - QStringList path = fname.split(QDir::separator(), QString::SkipEmptyParts); + QStringList path = fileName.split(QDir::separator(), QString::SkipEmptyParts); path.removeLast(); if (!QDir().mkpath(path.join("/"))) throw(DirException("Ini", path.join("/"))); - QFile fout(fname); + QFile fout(fileName); if (!fout.open(QIODevice::WriteOnly)) - throw(OpenException("Ini", fname)); + throw(OpenException("Ini", fileName)); save(fout); fout.close(); } @@ -82,96 +79,96 @@ void Ini::save(const QString& fname) const throw(Exception) void Ini::save(QFile& file) const { QTextStream fout(&file); - for (QMapIterator<QString, QString> i(fields); i.hasNext(); i.next()) - fout << i.key() << '=' << i.value() << '\n'; + foreach (QString field, m_fields) + fout << field << '=' << m_fields[field] << '\n'; fout << '\n'; } -void Ini::addField(const QString& n, const bool v) +void Ini::addField(const QString& field, const bool value) { - fields[n] = v ? "true" : "false"; + m_fields[field] = value ? "true" : "false"; } -void Ini::addField(const QString& n, const unsigned char v) +void Ini::addField(const QString& field, const unsigned char value) { - fields[n] = QString::number(v); + m_fields[field] = QString::number(value); } -void Ini::addField(const QString& n, const int v) +void Ini::addField(const QString& field, const int value) { - fields[n] = QString::number(v); + m_fields[field] = QString::number(value); } -void Ini::addField(const QString& n, const double v) +void Ini::addField(const QString& field, const double value) { - fields[n] = QString::number(v); + m_fields[field] = QString::number(value); } -void Ini::addField(const QString& n, const QString& v) +void Ini::addField(const QString& field, const QString& value) { - fields[n] = v; + m_fields[field] = value; } -void Ini::getValue(const QString& field, bool& val, const bool def) +void Ini::getValue(const QString& field, bool& value, const bool defaultValue) { - if (!fields.contains(field)) + if (!m_fields.contains(field)) { - val = def; + value = defaultValue; return; } - val = (fields[field] == "true") ? true : ((fields[field] == "false") ? false : def); + value = (m_fields[field] == "true") ? true : ((m_fields[field] == "false") ? false : defaultValue); } -void Ini::getValue(const QString& field, unsigned char& val, const unsigned char def) +void Ini::getValue(const QString& field, unsigned char& value, const unsigned char defaultValue) { - if (!fields.contains(field)) + if (!m_fields.contains(field)) { - val = def; + value = defaultValue; return; } bool ok; unsigned temp; - temp = fields[field].toUInt(&ok); - val = (ok && (temp <= UCHAR_MAX)) ? temp : def; + temp = m_fields[field].toUInt(&ok); + value = (ok && (temp <= UCHAR_MAX)) ? temp : defaultValue; } -void Ini::getValue(const QString& field, int& val, const int def) +void Ini::getValue(const QString& field, int& value, const int defaultValue) { - if (!fields.contains(field)) + if (!m_fields.contains(field)) { - val = def; + value = defaultValue; return; } bool ok; - val = fields[field].toInt(&ok); + value = m_fields[field].toInt(&ok); if (!ok) - val = def; + value = defaultValue; } -void Ini::getValue(const QString& field, double& val, const double def) +void Ini::getValue(const QString& field, double& value, const double defaultValue) { - if (!fields.contains(field)) + if (!m_fields.contains(field)) { - val = def; + value = defaultValue; return; } bool ok; - val = fields[field].toDouble(&ok); + value = m_fields[field].toDouble(&ok); if (!ok) - val = def; + value = defaultValue; } -void Ini::getValue(const QString& field, QString& val, const QString& def) +void Ini::getValue(const QString& field, QString& value, const QString& defaultValue) { - if (!fields.contains(field)) + if (!m_fields.contains(field)) { - val = def; + value = defaultValue; return; } - val = fields[field]; + value = m_fields[field]; } -QStringList Ini::getFields() const +QStringList Ini::fields() const { - return fields.keys(); + return m_fields.keys(); } diff --git a/general/Ini.h b/general/Ini.h index 5a695aff..741c5dfd 100644 --- a/general/Ini.h +++ b/general/Ini.h @@ -1,59 +1,55 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Ini.h -// Purpose: Define sections for data files -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri May 4 23:27:37 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __INI__ #define __INI__ +// Qt includes #include <QFile> #include <QMap> #include <QString> #include <QStringList> +// General includes #include "Exception.h" class Ini { public: Ini(); - Ini(const QString& fname) throw(Exception); + Ini(const QString& fileName) throw(Exception); - void load(const QString& fname) throw(Exception); - void save(const QString& fname) const throw(Exception); + void load(const QString& fileName) throw(Exception); + void save(const QString& fileName) const throw(Exception); - void addField(const QString& n, const bool v); - void addField(const QString& n, const unsigned char v); - void addField(const QString& n, const int v); - void addField(const QString& n, const double v); - void addField(const QString& n, const QString& v); + void addField(const QString& field, const bool value); + void addField(const QString& field, const unsigned char value); + void addField(const QString& field, const int value); + void addField(const QString& field, const double value); + void addField(const QString& field, const QString& value); - QString getName() const; - void getValue(const QString& field, bool& val, const bool def = true); - void getValue(const QString& field, unsigned char& val, const unsigned char def = UCHAR_MAX); - void getValue(const QString& field, int& val, const int def = -1); - void getValue(const QString& field, double& val, const double def = 0); - void getValue(const QString& field, QString& val, const QString& def = ""); + void getValue(const QString& field, bool& value, const bool defaultValue = true); + void getValue(const QString& field, unsigned char& value, const unsigned char defaultValue = 0); + void getValue(const QString& field, int& value, const int defaultValue = INT_MAX); + void getValue(const QString& field, double& value, const double defaultValue = 0); + void getValue(const QString& field, QString& value, const QString& defaultValue = ""); - QStringList getFields() const; - protected: + QStringList fields() const; + private: enum LinePos { Field = 0, @@ -63,7 +59,7 @@ class Ini void load(QFile& fin) throw(InvalidException); void save(QFile& fout) const; - QMap<QString, QString> fields; + QMap<QString, QString> m_fields; }; #endif diff --git a/general/Matrix.h b/general/Matrix.h index f1613c09..60398d26 100644 --- a/general/Matrix.h +++ b/general/Matrix.h @@ -1,193 +1,180 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Matrix.h -// Purpose: A 2D vector class -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sun Apr 8 12:51:20 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __MATRIX__ #define __MATRIX__ +// Qt includes +#include <QtGlobal> #include <QFile> -#include <QMutableVectorIterator> #include <QVector> -#include <QVectorIterator> +// General includes #include "Exception.h" template<class T> class Matrix { public: Matrix() : - width(0), - height(0) + m_width(0), + m_height(0) { } - Matrix(const int w, const int h, const T& d = T()) : - width(w), - height(h), - matrix(h, QVector<T>(w, d)) + Matrix(const int height, const int width, const T& value = T()) { - if (!width ^ !height) - { - if (width) - addRow(d); - if (height) - addCol(d); - } + resize(height, width, value); } - Matrix(const Matrix<T>& rhs) : - width(rhs.getWidth()), - height(rhs.getHeight()), - matrix(height, QVector<T>(width, T())) + Matrix(const Matrix<T>& rhs) { - for (int i = 0; i < height; ++i) - { - for (int j = 0; j < width; ++j) - matrix[i][j] = rhs(i, j); - } + *this = rhs; } - void addRow(const T& d = T()) + void addRow(const T& value = T()) { - width += !width; - matrix.append(QVector<T>(width, d)); - ++height; + m_width += !m_width; + m_matrix.append(QVector<T>(m_width, value)); + ++m_height; } - void addCol(const T& d = T()) + void addColumn(const T& value = T()) { - if (!height) + if (!m_height) { - matrix.append(QVector<T>()); - ++height; + m_matrix.append(QVector<T>()); + ++m_height; } - for (QMutableVectorIterator< QVector<T> > i(matrix); i.hasNext(); ) - i.next().append(d); - ++width; + foreach (QVector<T> row, m_matrix) + row.append(value); + ++m_width; } - void insertRow(const int pos, const T& d = T()) throw(BoundsException) + void insertRow(const int row, const T& value = T()) throw(BoundsException) { - if (height < pos) + if (m_height < row) throw(BoundsException("Matrix", "dimension")); - width += !width; - matrix.insert(pos, QVector<T>(width, d)); - ++height; + m_width += !m_width; + m_matrix.insert(row, QVector<T>(m_width, value)); + ++m_height; } - void insertCol(const int pos, const T& d = T()) throw(BoundsException) + void insertColumn(const int column, const T& value = T()) throw(BoundsException) { - if (width < pos) + if (m_width < column) throw(BoundsException("Matrix", "dimension")); - if (!height) + if (!m_height) { - matrix.append(QVector<T>()); - ++height; + m_matrix.append(QVector<T>()); + ++m_height; } - for (QMutableVectorIterator< QVector<T> > i(matrix); i.hasNext(); ) - i.next().insert(pos, d); - ++width; + foreach (QVector<T> row, m_matrix) + row.insert(column, value); + ++m_width; } - void deleteRow(const int pos) throw(BoundsException) + void deleteRow(const int row) throw(BoundsException) { - if (height <= pos) + if (m_height <= row) throw(BoundsException("Matrix", "dimension")); - matrix.remove(pos); - if (!(--height)) - width = 0; + m_matrix.remove(row); + if (!(--m_height)) + m_width = 0; } - void deleteCol(const int pos) throw(BoundsException) + void deleteColumn(const int column) throw(BoundsException) { - if (width <= pos) + if (m_width <= column) throw(BoundsException("Matrix", "dimension")); - for (QMutableVectorIterator< QVector<T> > i(matrix); i.hasNext(); ) - i.next().remove(pos); - if (!(--width)) - height = 0; + foreach (QVector<T> row, m_matrix) + row.remove(column); + if (!(--m_width)) + m_height = 0; } void clear() { - matrix.clear(); + m_width = 0; + m_height = 0; + m_matrix.clear(); } - void set(const int row, const int col, const T& s) throw(BoundsException) + void set(const int row, const int column, const T& value) throw(BoundsException) { - if ((height <= row) || (width <= col)) + if ((m_height <= row) || (m_width <= column)) throw(BoundsException("Matrix", "dimension")); - (*this)(row, col) = s; + (m_matrix[row])(column) = value; } - void resize(const int h, const int w, const T& d = T()) + void resize(const int height, const int width, const T& value = T()) { clear(); - width = w; - height = h; - matrix = QVector< QVector<T> >(h, QVector<T>(w, d)); + m_width = width; + m_height = height; + if (!m_width ^ !m_height) + { + if (m_width) + ++m_height; + if (m_height) + ++m_width; + } + m_matrix = QVector< QVector<T> >(m_height, QVector<T>(m_width, value)); } - const T& at(const int row, const int col) const throw(BoundsException) + const T& at(const int row, const int column) const throw(BoundsException) { - if ((height <= row) || (width <= col)) + if ((m_height <= row) || (m_width <= column)) throw(BoundsException("Matrix", "dimension")); - return matrix.at(row).at(col); + return m_matrix.at(row).at(column); } - const QVector<T> getRow(const int row) const throw(BoundsException) + const QVector<T> row(const int row) const throw(BoundsException) { if (height <= row) throw(BoundsException("Matrix", "dimension")); - return matrix.at(row); + return m_matrix.at(row); } - const QVector<T> getCol(const int col) const throw(BoundsException) + const QVector<T> column(const int column) const throw(BoundsException) { - if (width <= col) + if (m_width <= column) throw(BoundsException("Matrix", "dimension")); QVector<T> c; - for (QVectorIterator< QVector<T> > i(matrix); i.hasNext(); ) - c.append(i.next().at(col)); + foreach (QVector<T> row, m_matrix) + c.append(row.at(column)); return c; } - int getHeight() const + int height() const { - return height; + return m_height; } - int getWidth() const + int width() const { - return width; + return m_width; } - T& operator()(const int row, const int col) throw(BoundsException) + T& operator()(const int row, const int column) throw(BoundsException) { - if ((height <= row) || (width <= col)) + if ((m_height <= row) || (m_width <= column)) throw(BoundsException("Matrix", "dimension")); - return (matrix[row])[col]; + return (m_matrix[row])[column]; } - const T& operator()(const int row, const int col) const + const T& operator()(const int row, const int column) const { - return at(row, col); + return at(row, column); } Matrix<T> operator=(const Matrix<T>& rhs) { if (this == &rhs) return *this; - height = rhs.getHeight(); - width = rhs.getWidth(); - resize(height, width); - for (int i = 0; i < height; ++i) + resize(rhs.m_height, rhs.m_width); + for (int i = 0; i < m_height; ++i) { - for (int j = 0; j < width; ++j) - matrix[i][j] = rhs(i, j); + for (int j = 0; j < m_width; ++j) + m_matrix[i][j] = rhs(i, j); } return *this; } @@ -195,13 +182,13 @@ template<class T> class Matrix { if (this == &rhs) return true; - if ((height != rhs.getHeight()) || (width == rhs.getWidth())) + if ((m_height != rhs.m_height) || (m_width == rhs.m_width)) return false; - for (int i = 0; i < height; ++i) + for (int i = 0; i < m_height; ++i) { - for (int j = 0; j < width; ++j) + for (int j = 0; j < m_width; ++j) { - if (matrix[i][j] != rhs(i, j)) + if (m_matrix[i][j] != rhs(i, j)) return false; } } @@ -212,9 +199,9 @@ template<class T> class Matrix return !(*this == rhs); } protected: - int width; - int height; - QVector< QVector<T> > matrix; + int m_width; + int m_height; + QVector< QVector<T> > m_matrix; }; #endif diff --git a/general/Point.h b/general/Point.h index 209c3f6e..0525f85b 100644 --- a/general/Point.h +++ b/general/Point.h @@ -1,64 +1,78 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: general/Point.h -// Purpose: Define a coordinate point -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sun Apr 8 12:53:15 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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 __POINT__ #define __POINT__ -#include <QFile> - class Point { public: - Point(const int _x = 0, const int _y = 0) : - x(_x), - y(_y) + inline Point(const int x = 0, const int y = 0) : + m_x(x), + m_y(y) + { + } + inline Point(const Point& rhs) { + *this = rhs; } - void set(const int _x, const int _y) + inline void set(const int x, const int y) + { + m_x = x; + m_y = y; + } + inline void setX(const int x) { - x = _x; - y = _y; + m_x = x; } - void setX(const int _x) + inline void setY(const int y) { - x = _x; + m_y = y; } - void setY(const int _y) + + inline int x() const + { + return m_x; + } + inline int y() const { - y = _y; + return m_y; } - int getX() const + Point& operator=(const Point& rhs) + { + if (this == &rhs) + return *this; + m_x = rhs.m_x; + m_y = rhs.m_y; + return *this; + } + inline bool operator==(const Point& rhs) const { - return x; + return ((m_x == rhs.m_x) && (m_y == rhs.m_y)); } - int getY() const + inline bool operator!=(const Point& rhs) const { - return y; + return !(*this == rhs); } private: - int x; - int y; + int m_x; + int m_y; }; #endif diff --git a/general/TODO b/general/TODO new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/general/TODO diff --git a/general/general.pro b/general/general.pro index 307f78e1..1b774ecf 100644 --- a/general/general.pro +++ b/general/general.pro @@ -67,3 +67,5 @@ HEADERS += Audio.h \ INSTALLS += target target.path = /usr/lib`kde4-config --libsuffix` +DISTFILES += TODO + diff --git a/pokemod/Ability.cpp b/pokemod/Ability.cpp index 8cc1a319..ee2feeea 100644 --- a/pokemod/Ability.cpp +++ b/pokemod/Ability.cpp @@ -1,215 +1,209 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Ability.cpp -// Purpose: Define an ability that species can possess to add extra -// dynamics to the battle system -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:41:10 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> #include <QStringList> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "AbilityEffect.h" + +// Header include #include "Ability.h" -Ability::Ability(const Pokemod* par, const int _id) : - Object("Ability", par, _id), - name("") +Ability::Ability(const Pokemod* pokemod, const int id) : + Object("Ability", pokemod, id), + m_name("") { } -Ability::Ability(const Pokemod* par, const Ability& a, const int _id) : - Object("Ability", par, _id) +Ability::Ability(const Pokemod* pokemod, const Ability& ability, const int id) : + Object("Ability", pokemod, id) { - *this = a; + *this = ability; } -Ability::Ability(const Pokemod* par, const QString& fname, const int _id) : - Object("Ability", par, _id) +Ability::Ability(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Ability", pokemod, id) { - load(fname, _id); + load(fileName, id); } Ability::~Ability() { - for (QListIterator<AbilityEffect*> i(effects); i.hasNext(); ) - delete i.next(); + foreach (AbilityEffect* effect, m_effects) + delete effect; } bool Ability::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Ability \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Ability \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("No Name"); + pokemod()->validationMsg("No Name"); valid = false; } - if (getEffectCount()) + if (effectCount()) { - QMap<int, int> idChecker; - for (QListIterator<AbilityEffect*> i(effects); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + foreach (AbilityEffect* effect, m_effects) { - if (1 < i.value()) - { - pokemod->validationMsg(QString("%2 effects with id %3").arg(name).arg(i.value()).arg(i.key())); + if (!effect->isValid()) valid = false; - } + if (idChecker[effect->id()]) + pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); + idChecker[effect->id()] = true; } } else { - pokemod->validationMsg(QString("No effects").arg(name)); + pokemod()->validationMsg(QString("No effects")); valid = false; } return valid; } -int Ability::getNewId() const -{ - int i = 0; - for (; (i < getEffectCount()) && (getEffectIndex(i) != -1); ++i) - ; - return i; -} - -void Ability::load(const QString& fname, const int _id) throw(Exception) +void Ability::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) - ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - QStringList path = pokemod->getPath().split('/'); + Ini ini(fileName); + if (id == INT_MAX) + ini.getValue("id", id, INT_MAX); + setId(id); + ini.getValue("name", m_name); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - effects.clear(); + m_effects.clear(); if (fdir.cd("effect")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEffect(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newEffect(file); } } void Ability::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.save(QString("%1/ability/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<AbilityEffect*> i(effects); i.hasNext(); ) - i.next()->save(name); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.save(QString("%1/ability/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (AbilityEffect* effect, m_effects) + effect->save(m_name); } -void Ability::setName(const QString& n) +void Ability::setName(const QString& name) { - name = n; + m_name = name; } -QString Ability::getName() const +QString Ability::name() const { - return name; + return m_name; } -const AbilityEffect* Ability::getEffect(const int i) const throw(IndexException) +const AbilityEffect* Ability::effect(const int index) const throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects.at(i); + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects.at(index); } -AbilityEffect* Ability::getEffect(const int i) throw(IndexException) +AbilityEffect* Ability::effect(const int index) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects[i]; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects[index]; } -const AbilityEffect* Ability::getEffectByID(const int i) const throw(IndexException) +const AbilityEffect* Ability::effectById(const int id) const throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(id)); } -AbilityEffect* Ability::getEffectByID(const int i) throw(IndexException) +AbilityEffect* Ability::effectById(const int id) throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(id)); } -int Ability::getEffectIndex(const int _id) const +int Ability::effectIndex(const int id) const { - for (int i = 0; i < getEffectCount(); ++i) + for (int i = 0; i < effectCount(); ++i) { - if (effects[i]->getId() == _id) + if (m_effects[id]->id() == id) return i; } - return -1; + return INT_MAX; } -int Ability::getEffectCount() const +int Ability::effectCount() const { - return effects.size(); + return m_effects.size(); } AbilityEffect* Ability::newEffect() { - effects.append(new AbilityEffect(pokemod, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new AbilityEffect(pokemod(), effectId())); + return m_effects[effectCount() - 1]; } -AbilityEffect* Ability::newEffect(const QString& fname) +AbilityEffect* Ability::newEffect(const QString& fileName) { - effects.append(new AbilityEffect(pokemod, fname, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new AbilityEffect(pokemod(), fileName, effectId())); + return m_effects[effectCount() - 1]; } -AbilityEffect* Ability::newEffect(const AbilityEffect& e) +AbilityEffect* Ability::newEffect(const AbilityEffect& effect) { - effects.append(new AbilityEffect(pokemod, e, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new AbilityEffect(pokemod(), effect, effectId())); + return m_effects[effectCount() - 1]; } -void Ability::deleteEffect(const int i) throw(IndexException) +void Ability::deleteEffect(const int index) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - delete effects[i]; - effects.removeAt(i); + if (effectCount() <= index) + throw(IndexException(className())); + delete m_effects[index]; + m_effects.removeAt(index); +} + +void Ability::deleteEffectById(const int id) throw(IndexException) +{ + deleteEffect(effectIndex(id)); +} + +int Ability::effectId() const +{ + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; } Ability& Ability::operator=(const Ability& rhs) { if (this == &rhs) return *this; - name = rhs.name; - effects.clear(); - for (int i = 0; i < rhs.getEffectCount(); ++i) - effects.append(new AbilityEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); + m_name = rhs.m_name; + m_effects.clear(); + foreach (AbilityEffect* effect, rhs.m_effects) + m_effects.append(new AbilityEffect(pokemod(), *effect, effect->id())); return *this; } diff --git a/pokemod/Ability.h b/pokemod/Ability.h index ed7af6eb..6e8663da 100644 --- a/pokemod/Ability.h +++ b/pokemod/Ability.h @@ -1,73 +1,72 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Ability.h -// Purpose: Define an ability that species can possess to add extra -// dynamics to the battle system -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:41:10 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class AbilityEffect; class Pokemod; class Ability : public Object { public: - Ability(const Pokemod* par, const int _id); - Ability(const Pokemod* par, const Ability& a, const int _id); - Ability(const Pokemod* par, const QString& fname, const int _id = -1); + Ability(const Pokemod* pokemod, const int id); + Ability(const Pokemod* pokemod, const Ability& ability, const int id); + Ability(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~Ability(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); + void setName(const QString& name); - QString getName() const; + QString name() const; - const AbilityEffect* getEffect(const int i) const throw(IndexException); - AbilityEffect* getEffect(const int i) throw(IndexException); - const AbilityEffect* getEffectByID(const int i) const throw(IndexException); - AbilityEffect* getEffectByID(const int i) throw(IndexException); - int getEffectIndex(const int _id) const; - int getEffectCount() const; + const AbilityEffect* effect(const int index) const throw(IndexException); + AbilityEffect* effect(const int index) throw(IndexException); + const AbilityEffect* effectById(const int id) const throw(IndexException); + AbilityEffect* effectById(const int id) throw(IndexException); + int effectIndex(const int id) const; + int effectCount() const; AbilityEffect* newEffect(); - AbilityEffect* newEffect(const QString& fname); - AbilityEffect* newEffect(const AbilityEffect& a); - void deleteEffect(const int i) throw(IndexException); + AbilityEffect* newEffect(const QString& fileName); + AbilityEffect* newEffect(const AbilityEffect& effect); + void deleteEffect(const int index) throw(IndexException); + void deleteEffectById(const int id) throw(IndexException); Ability& operator=(const Ability& rhs); private: bool validate() const; - int getNewId() const; + int effectId() const; - QString name; + QString m_name; - QList<AbilityEffect*> effects; + QList<AbilityEffect*> m_effects; }; #endif diff --git a/pokemod/AbilityEffect.cpp b/pokemod/AbilityEffect.cpp index c4f5c470..e9ae084e 100644 --- a/pokemod/AbilityEffect.cpp +++ b/pokemod/AbilityEffect.cpp @@ -1,28 +1,26 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/AbilityEffect.cpp -// Purpose: Define an effect of an ability -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Thu Mar 22 19:06:58 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ -#include "Pokemod.h" +// Pokemod includes #include "Ability.h" +#include "Pokemod.h" #include "Type.h" + +// Header include #include "AbilityEffect.h" const QStringList AbilityEffect::EffectStr = QStringList() << "Damage to HP" << "Prevent Damage" << "Auto Heal" << "Deal Damage" << "Wilds" << "Stat" << "Status" << "Ability" << "Accuracy/Power Trade" << "Bullseye" << "Item Effect" << "Type" << "Fast Hatch" << "Weather"; @@ -35,102 +33,102 @@ const QStringList AbilityEffect::BoostStr = QStringList() << "Boost" << "Hinder" const QStringList AbilityEffect::SideStr = QStringList() << "Above" << "Below"; -AbilityEffect::AbilityEffect(const Pokemod* par, const int _id) : - Object("AbilityEffect", par, _id), - chance(1, 1), - effect(-1), - val1(-1), - val2(-1), - val3(-1), - trigger(-1), - tval1(-1), - tval2(-1) +AbilityEffect::AbilityEffect(const Pokemod* pokemod, const int id) : + Object("AbilityEffect", pokemod, id), + m_chance(1, 1), + m_effect(INT_MAX), + m_value1(INT_MAX), + m_value2(INT_MAX), + m_value3(INT_MAX), + m_trigger(INT_MAX), + m_triggerValue1(INT_MAX), + m_triggerValue2(INT_MAX) { } -AbilityEffect::AbilityEffect(const Pokemod* par, const AbilityEffect& e, const int _id) : - Object("AbilityEffect", par, _id) +AbilityEffect::AbilityEffect(const Pokemod* pokemod, const AbilityEffect& effect, const int id) : + Object("AbilityEffect", pokemod, id) { - *this = e; + *this = effect; } -AbilityEffect::AbilityEffect(const Pokemod* par, const QString& fname, const int _id) : - Object("AbilityEffect", par, _id) +AbilityEffect::AbilityEffect(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("AbilityEffect", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool AbilityEffect::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Effect with id %1---").arg(id), Pokemod::V_Msg); - if (effect < E_End) + pokemod()->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); + if (m_effect < E_End) { bool ok = true; - switch (effect) + switch (m_effect) { case E_Stats: - if ((Pokemod::ST_HP == val1) || (Pokemod::ST_End_Battle <= val1) || ((val1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) + if ((Pokemod::ST_HP == m_value1) || (Pokemod::ST_End_Battle <= m_value1) || ((Pokemod::ST_SpecialDefense == m_value1) && !pokemod()->rules()->specialSplit())) ok = false; break; case E_Status: - if (Pokemod::STS_End <= val1) + if (Pokemod::STS_End <= m_value1) ok = false; break; case E_Ability: - if (pokemod->getAbilityIndex(val1) == -1) + if (pokemod()->abilityIndex(m_value1) == INT_MAX) ok = false; break; case E_AccuracyPowerTrade: - if (PA_End <= val1) + if (PA_End <= m_value1) ok = false; break; case E_ItemEffect: - if (IT_End <= val1) + if (IT_End <= m_value1) ok = false; break; case E_Type: - if (pokemod->getTypeIndex(val1) == -1) + if (pokemod()->typeIndex(m_value1) == INT_MAX) ok = false; break; case E_Weather: - if (Pokemod::W_End_All <= val1) + if (Pokemod::W_End_All <= m_value1) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid value1"); + pokemod()->validationMsg("Invalid value 1"); valid = false; ok = true; } - switch (effect) + switch (m_effect) { case E_Stats: - if (Pokemod::BM_End <= val2) + if (Pokemod::BM_End <= m_value2) ok = false; break; case E_Status: case E_Weather: - if (C_End <= val2) + if (C_End <= m_value2) ok = false; break; case E_Ability: - if (I_End <= val2) + if (I_End <= m_value2) ok = false; break; case E_Type: - if (B_End <= val2) + if (B_End <= m_value2) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid value2"); + pokemod()->validationMsg("Invalid value 2"); valid = false; ok = true; } - switch (effect) + switch (m_effect) { case E_DamageToHP: case E_PreventDamage: @@ -140,201 +138,190 @@ bool AbilityEffect::validate() const case E_AccuracyPowerTrade: case E_Type: case E_FastHatch: - if ((val3 < 0) || (100 < val3)) + if ((m_value3 < 0) || (100 < m_value3)) ok = false; break; case E_Stats: - if ((val3 < -12) || (12 < val3)) + if ((m_value3 < -12) || (12 < m_value3)) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid value3"); + pokemod()->validationMsg("Invalid value 3"); valid = false; ok = true; } } else { - pokemod->validationMsg("Invalid effect"); + pokemod()->validationMsg("Invalid effect"); valid = false; } - if (trigger < T_End) + if (m_trigger < T_End) { bool ok = true; - switch (trigger) + switch (m_trigger) { case T_Weather: - if (Pokemod::W_End_All <= tval1) + if (Pokemod::W_End_All <= m_triggerValue1) ok = false; break; case T_Type: - if (pokemod->getTypeIndex(tval1) == -1) + if (pokemod()->typeIndex(m_triggerValue1) == INT_MAX) ok = false; break; case T_HPBoundary: - if (S_End <= tval1) + if (S_End <= m_triggerValue1) ok = false; break; case T_StatChange: - if ((Pokemod::ST_HP == tval1) || (Pokemod::ST_End_Battle <= tval1) || ((tval1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) + if ((Pokemod::ST_HP == m_triggerValue1) || (Pokemod::ST_End_Battle <= m_triggerValue1) || ((Pokemod::ST_SpecialDefense == m_triggerValue1) && !pokemod()->rules()->specialSplit())) ok = false; break; case T_Status: - if (Pokemod::STS_End <= tval1) + if (Pokemod::STS_End <= m_triggerValue1) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid trigger value1"); + pokemod()->validationMsg("Invalid trigger value 1"); valid = false; } } else { - pokemod->validationMsg("Invalid trigger"); + pokemod()->validationMsg("Invalid trigger"); valid = false; } return valid; } -void AbilityEffect::load(const QString& fname, const int _id) throw(Exception) +void AbilityEffect::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; ini.getValue("chance-n", i, 1); ini.getValue("chance-d", j, 1); - chance.set(i, j); - ini.getValue("effect", effect); - ini.getValue("val1", val1); - ini.getValue("val2", val2); - ini.getValue("val3", val3); - ini.getValue("trigger", trigger); - ini.getValue("tval1", tval1); - ini.getValue("tval2-n", i, 1); - ini.getValue("tval2-d", j, 1); - tval2.set(i, j); + m_chance.set(i, j); + ini.getValue("effect", m_effect); + ini.getValue("value1", m_value1); + ini.getValue("value2", m_value2); + ini.getValue("value3", m_value3); + ini.getValue("trigger", m_trigger); + ini.getValue("triggerValue1", m_triggerValue1); + ini.getValue("triggerValue2-n", i, 1); + ini.getValue("triggerValue2-d", j, 1); + m_triggerValue2.set(i, j); } void AbilityEffect::save(const QString& ability) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("chance-n", chance.getNum()); - ini.addField("chance-d", chance.getDenom()); - ini.addField("effect", effect); - ini.addField("val1", val1); - ini.addField("val2", val2); - ini.addField("val3", val3); - ini.addField("trigger", trigger); - ini.addField("tval1", tval1); - ini.addField("tval2-n", tval2.getNum()); - ini.addField("tval2-d", tval2.getDenom()); - ini.save(QString("%1/ability/%2/effect/%3.pini").arg(pokemod->getPath()).arg(ability).arg(id)); -} - -void AbilityEffect::setChance(const int n, const int d) throw(Exception) -{ - chance.set(n, d); -} - -void AbilityEffect::setChanceNum(const int n) throw(Exception) -{ - chance.setNum(n); + ini.addField("id", id()); + ini.addField("chance-n", m_chance.numerator()); + ini.addField("chance-d", m_chance.denominator()); + ini.addField("effect", m_effect); + ini.addField("value1", m_value1); + ini.addField("value2", m_value2); + ini.addField("value3", m_value3); + ini.addField("trigger", m_trigger); + ini.addField("triggerValue1", m_triggerValue1); + ini.addField("triggerValue2-n", m_triggerValue2.numerator()); + ini.addField("triggerValue2-d", m_triggerValue2.denominator()); + ini.save(QString("%1/ability/%2/effect/%3.pini").arg(pokemod()->path()).arg(ability).arg(id())); } -void AbilityEffect::setChanceDenom(const int d) throw(Exception) +void AbilityEffect::setChance(const int numerator, const int denominator) throw(Exception) { - chance.setDenom(d); + m_chance.set(numerator, denominator); } -void AbilityEffect::setEffect(const int e) throw(BoundsException) +void AbilityEffect::setEffect(const int effect) throw(BoundsException) { - if (E_End <= e) - throw(BoundsException(className, "effect")); - effect = e; - val1 = -1; - val2 = -1; - val3 = 0; + if (E_End <= effect) + throw(BoundsException(className(), "effect")); + m_effect = effect; + m_value1 = INT_MAX; + m_value2 = INT_MAX; + m_value3 = 0; } -void AbilityEffect::setVal1(const int v1) throw(Exception) +void AbilityEffect::setValue1(const int value1) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Stats: - if ((Pokemod::ST_HP == val1) || (Pokemod::ST_End_Battle <= val1) || ((val1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "val1")); + if ((Pokemod::ST_HP == value1) || (Pokemod::ST_End_Battle <= value1) || ((Pokemod::ST_SpecialDefense == value1) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "value1")); break; case E_Status: - if (Pokemod::STS_End <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::STS_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Ability: - if (pokemod->getAbilityIndex(v1) == -1) - throw(BoundsException(className, "val1")); + if (pokemod()->abilityIndex(value1) == INT_MAX) + throw(BoundsException(className(), "value1")); break; case E_AccuracyPowerTrade: - if (PA_End <= v1) - throw(BoundsException(className, "val1")); + if (PA_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_ItemEffect: - if (IT_End <= v1) - throw(BoundsException(className, "val1")); + if (IT_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Type: - if (pokemod->getTypeIndex(v1) == -1) - throw(BoundsException(className, "val1")); + if (pokemod()->typeIndex(value1) == INT_MAX) + throw(BoundsException(className(), "value1")); break; case E_Weather: - if (Pokemod::W_End_All <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::W_End_All <= value1) + throw(BoundsException(className(), "value1")); break; default: - throw(UnusedException(className, "val1")); + throw(UnusedException(className(), "value1")); break; } - val1 = v1; + m_value1 = value1; } -void AbilityEffect::setVal2(const int v2) throw(Exception) +void AbilityEffect::setValue2(const int value2) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Stats: - if (Pokemod::BM_End <= v2) - throw(BoundsException(className, "val2")); + if (Pokemod::BM_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Status: case E_Weather: - if (C_End <= v2) - throw(BoundsException(className, "val2")); + if (C_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Ability: - if (I_End <= v2) - throw(BoundsException(className, "val2")); + if (I_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Type: - if (B_End <= v2) - throw(BoundsException(className, "val2")); + if (B_End <= value2) + throw(BoundsException(className(), "value2")); break; default: - throw(UnusedException(className, "val2")); + throw(UnusedException(className(), "value2")); break; } - val2 = v2; + m_value2 = value2; } -void AbilityEffect::setVal3(const int v3) throw(Exception) +void AbilityEffect::setValue3(const int value3) throw(Exception) { - switch (effect) + switch (m_effect) { case E_DamageToHP: case E_PreventDamage: @@ -344,132 +331,118 @@ void AbilityEffect::setVal3(const int v3) throw(Exception) case E_AccuracyPowerTrade: case E_Type: case E_FastHatch: - if ((v3 < 0) || (100 < v3)) - throw(BoundsException(className, "val3")); + if ((value3 < 0) || (100 < value3)) + throw(BoundsException(className(), "value3")); break; case E_Stats: - if ((v3 < -12) || (12 < v3)) - throw(BoundsException(className, "val3")); + if ((value3 < -12) || (12 < value3)) + throw(BoundsException(className(), "value3")); break; default: - throw(UnusedException(className, "val3")); + throw(UnusedException(className(), "value3")); break; } - val3 = v3; + m_value3 = value3; } -void AbilityEffect::setTrigger(const int t) throw(BoundsException) +void AbilityEffect::setTrigger(const int trigger) throw(BoundsException) { - if (T_End <= t) - throw(BoundsException(className, "trigger")); - trigger = t; - tval1 = -1; - tval2.set(1, 1); + if (T_End <= trigger) + throw(BoundsException(className(), "trigger")); + m_trigger = trigger; + m_triggerValue1 = INT_MAX; + m_triggerValue2.set(1, 1); } -void AbilityEffect::setTval1(const int tv1) throw(Exception) +void AbilityEffect::setTriggerValue1(const int triggerValue1) throw(Exception) { - switch (trigger) + switch (m_trigger) { case T_Weather: - if (Pokemod::W_End_All <= tv1) - throw(BoundsException(className, "tval1")); + if (Pokemod::W_End_All <= triggerValue1) + throw(BoundsException(className(), "triggerValue1")); break; case T_Type: - if (pokemod->getTypeIndex(tv1) == -1) - throw(BoundsException(className, "tval1")); + if (pokemod()->typeIndex(triggerValue1) == INT_MAX) + throw(BoundsException(className(), "triggerValue1")); break; case T_HPBoundary: - if (S_End <= tv1) - throw(BoundsException(className, "tval1")); + if (S_End <= triggerValue1) + throw(BoundsException(className(), "triggerValue1")); break; case T_StatChange: - if ((Pokemod::ST_HP == tval1) || (Pokemod::ST_End_Battle <= tval1) || ((tval1 == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "tval1")); + if ((Pokemod::ST_HP == triggerValue1) || (Pokemod::ST_End_Battle <= triggerValue1) || ((Pokemod::ST_SpecialDefense == triggerValue1) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "triggerValue1")); break; case T_Status: - if (Pokemod::STS_End <= tv1) - throw(BoundsException(className, "tval1")); + if (Pokemod::STS_End <= triggerValue1) + throw(BoundsException(className(), "triggerValue1")); break; default: - throw(UnusedException(className, "tval1")); + throw(UnusedException(className(), "triggerValue1")); break; } - tval1 = tv1; -} - -void AbilityEffect::setTval2(const int n, const int d) throw(Exception) -{ - if (trigger != T_HPBoundary) - throw(UnusedException(className, "tval2")); - tval2.set(n, d); -} - -void AbilityEffect::setTval2Num(const int n) throw(Exception) -{ - if (trigger != T_HPBoundary) - throw(UnusedException(className, "tval2")); - tval2.setNum(n); + m_triggerValue1 = triggerValue1; } -void AbilityEffect::setTval2Denom(const int d) throw(Exception) +void AbilityEffect::setTriggerValue2(const int numerator, const int denominator) throw(Exception) { - if (trigger != T_HPBoundary) - throw(UnusedException(className, "tval2")); - tval2.setDenom(d); + if (m_trigger != T_HPBoundary) + throw(UnusedException(className(), "triggerValue2")); + m_triggerValue2.set(numerator, denominator); } -Frac AbilityEffect::getChance() const +Frac AbilityEffect::chance() const { - return chance; + return m_chance; } -int AbilityEffect::getEffect() const +int AbilityEffect::effect() const { - return effect; + return m_effect; } -int AbilityEffect::getVal1() const +int AbilityEffect::value1() const { - return val1; + return m_value1; } -int AbilityEffect::getVal2() const +int AbilityEffect::value2() const { - return val2; + return m_value2; } -int AbilityEffect::getVal3() const +int AbilityEffect::value3() const { - return val3; + return m_value3; } -int AbilityEffect::getTrigger() const +int AbilityEffect::trigger() const { - return trigger; + return m_trigger; } -int AbilityEffect::getTval1() const +int AbilityEffect::triggerValue1() const { - return tval1; + return m_triggerValue1; } -Frac AbilityEffect::getTval2() const +Frac AbilityEffect::triggerValue2() const { - return tval2; + return m_triggerValue2; } AbilityEffect& AbilityEffect::operator=(const AbilityEffect& rhs) { if (this == &rhs) return *this; - chance = rhs.chance; - effect = rhs.effect; - val1 = rhs.val1; - val2 = rhs.val2; - val3 = rhs.val3; - trigger = rhs.trigger; - tval1 = rhs.tval1; - tval2 = rhs.tval2; + m_chance = rhs.m_chance; + m_effect = rhs.m_effect; + m_value1 = rhs.m_value1; + m_value2 = rhs.m_value2; + m_value3 = rhs.m_value3; + m_trigger = rhs.m_trigger; + m_triggerValue1 = rhs.m_triggerValue1; + m_triggerValue2 = rhs.m_triggerValue2; return *this; } diff --git a/pokemod/AbilityEffect.h b/pokemod/AbilityEffect.h index 81c63055..deb5a8c9 100644 --- a/pokemod/AbilityEffect.h +++ b/pokemod/AbilityEffect.h @@ -1,36 +1,35 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/AbilityEffect.h -// Purpose: Define an effect of an ability -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Thu Mar 22 19:06:58 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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_ABILITYEFFECT__ #define __POKEMOD_ABILITYEFFECT__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class AbilityEffect : public Object @@ -121,47 +120,43 @@ class AbilityEffect : public Object }; static const QStringList SideStr; - AbilityEffect(const Pokemod* par, const int _id); - AbilityEffect(const Pokemod* par, const AbilityEffect& e, const int _id); - AbilityEffect(const Pokemod* par, const QString& fname, const int _id = -1); + AbilityEffect(const Pokemod* pokemod, const int id); + AbilityEffect(const Pokemod* pokemod, const AbilityEffect& effect, const int id); + AbilityEffect(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& ability) const throw(Exception); - void setChance(const int n, const int d) throw(Exception); - void setChanceNum(const int n) throw(Exception); - void setChanceDenom(const int d) throw(Exception); - void setEffect(const int e) throw(BoundsException); - void setVal1(const int v1) throw(Exception); - void setVal2(const int v2) throw(Exception); - void setVal3(const int v3) throw(Exception); - void setTrigger(const int t) throw(BoundsException); - void setTval1(const int tv1) throw(Exception); - void setTval2(const int n, const int d) throw(Exception); - void setTval2Num(const int n) throw(Exception); - void setTval2Denom(const int d) throw(Exception); + void setChance(const int numerator, const int denominator) throw(Exception); + void setEffect(const int effect) throw(BoundsException); + void setValue1(const int value1) throw(Exception); + void setValue2(const int value2) throw(Exception); + void setValue3(const int value3) throw(Exception); + void setTrigger(const int trigger) throw(BoundsException); + void setTriggerValue1(const int triggerValue1) throw(Exception); + void setTriggerValue2(const int numerator, const int denominator) throw(Exception); - Frac getChance() const; - int getEffect() const; - int getVal1() const; - int getVal2() const; - int getVal3() const; - int getTrigger() const; - int getTval1() const; - Frac getTval2() const; + Frac chance() const; + int effect() const; + int value1() const; + int value2() const; + int value3() const; + int trigger() const; + int triggerValue1() const; + Frac triggerValue2() const; AbilityEffect& operator=(const AbilityEffect& rhs); private: bool validate() const; - Frac chance; - int effect; - int val1; - int val2; - int val3; - int trigger; - int tval1; - Frac tval2; + Frac m_chance; + int m_effect; + int m_value1; + int m_value2; + int m_value3; + int m_trigger; + int m_triggerValue1; + Frac m_triggerValue2; }; #endif diff --git a/pokemod/Author.cpp b/pokemod/Author.cpp index a701e535..7f170cef 100644 --- a/pokemod/Author.cpp +++ b/pokemod/Author.cpp @@ -1,132 +1,130 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Author.cpp -// Purpose: Define an author of a PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 20:42:17 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Qt includes #include <QRegExp> +// Pokemod includes #include "Pokemod.h" + +// Header include #include "Author.h" -Author::Author(const Pokemod* par, const int _id) : - Object("Author", par, _id), - name(""), - email(""), - role("") +Author::Author(const Pokemod* pokemod, const int id) : + Object("Author", pokemod, id), + m_name(""), + m_email(""), + m_role("") { } -Author::Author(const Pokemod* par, const Author& a, const int _id) : - Object("Author", par, _id) +Author::Author(const Pokemod* pokemod, const Author& author, const int id) : + Object("Author", pokemod, id) { - *this = a; + *this = author; } -Author::Author(const Pokemod* par, const QString& fname, const int _id) : - Object("Author", par, _id) +Author::Author(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Author", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Author::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Author \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Author \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name not defined"); + pokemod()->validationMsg("Name not defined"); valid = false; } - if (email == "") - pokemod->validationMsg("Email not defined", Pokemod::V_Warn); - else if (!QRegExp("[a-zA-Z0-9%-_\\.]+@[a-zA-Z0-9\\-]+(\\.[a-zA-Z]+)*\\.[a-zA-Z]{2,4}").exactMatch(email)) + if (m_email == "") + pokemod()->validationMsg("Email not defined", Pokemod::V_Warn); + else if (!QRegExp("[a-zA-Z0-9%-_\\.]+@[a-zA-Z0-9\\-]+(\\.[a-zA-Z]+)*\\.[a-zA-Z]{2,4}").exactMatch(m_email)) { - pokemod->validationMsg("Invalid email"); + pokemod()->validationMsg("Invalid email"); valid = false; } - if (role == "") + if (m_role == "") { - pokemod->validationMsg("Role not defined"); + pokemod()->validationMsg("Role not defined"); valid = false; } return valid; } -void Author::load(const QString& fname, const int _id) throw(Exception) +void Author::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - ini.getValue("email", email); - ini.getValue("role", role); + setId(id); + ini.getValue("name", m_name); + ini.getValue("email", m_email); + ini.getValue("role", m_role); } void Author::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("email", email); - ini.addField("role", role); - ini.save(QString("%1/author/%2.pini").arg(pokemod->getPath()).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("email", m_email); + ini.addField("role", m_role); + ini.save(QString("%1/author/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Author::setName(const QString& n) +void Author::setName(const QString& name) { - name = n; + m_name = name; } -void Author::setEmail(const QString& e) +void Author::setEmail(const QString& email) { - email = e; + m_email = email; } -void Author::setRole(const QString& r) +void Author::setRole(const QString& role) { - role = r; + m_role = role; } -QString Author::getName() const +QString Author::name() const { - return name; + return m_name; } -QString Author::getEmail() const +QString Author::email() const { - return email; + return m_email; } -QString Author::getRole() const +QString Author::role() const { - return role; + return m_role; } Author& Author::operator=(const Author& rhs) { if (this == &rhs) return *this; - name = rhs.name; - email = rhs.email; - role = rhs.role; + m_name = rhs.m_name; + m_email = rhs.m_email; + m_role = rhs.m_role; return *this; } diff --git a/pokemod/Author.h b/pokemod/Author.h index c96656fa..ca58fe6b 100644 --- a/pokemod/Author.h +++ b/pokemod/Author.h @@ -1,59 +1,57 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Author.h -// Purpose: Define an author of a PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 20:42:17 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class Author : public Object { public: - Author(const Pokemod* par, const int _id); - Author(const Pokemod* par, const Author& a, const int _id); - Author(const Pokemod* par, const QString& fname, const int _id = -1); + Author(const Pokemod* pokemod, const int id); + Author(const Pokemod* pokemod, const Author& author, const int id); + Author(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setEmail(const QString& e); - void setRole(const QString& r); + void setName(const QString& name); + void setEmail(const QString& email); + void setRole(const QString& role); - QString getName() const; - QString getEmail() const; - QString getRole() const; + QString name() const; + QString email() const; + QString role() const; Author& operator=(const Author& rhs); private: bool validate() const; - QString name; - QString email; - QString role; + QString m_name; + QString m_email; + QString m_role; }; #endif diff --git a/pokemod/Badge.cpp b/pokemod/Badge.cpp index 2868f93d..8e679aa2 100644 --- a/pokemod/Badge.cpp +++ b/pokemod/Badge.cpp @@ -1,216 +1,196 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Badge.cpp -// Purpose: Define a badge which can boost some stats and can allow the -// use of special techniques in the overworld -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:27:53 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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" -Badge::Badge(const Pokemod* par, const int _id) : - Object("Badge", par, _id), - name(""), - obey(0) +Badge::Badge(const Pokemod* pokemod, const int id) : + Object("Badge", pokemod, id), + m_name(""), + m_obey(0) { for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - stats[i].set(1, 1); + m_stats[i].set(1, 1); for (int i = 0; i < Pokemod::HM_End_All; ++i) - hm[i] = false; + m_hm[i] = false; } -Badge::Badge(const Pokemod* par, const Badge& b, const int _id) : - Object("Badge", par, _id) +Badge::Badge(const Pokemod* pokemod, const Badge& badge, const int id) : + Object("Badge", pokemod, id) { - *this = b; + *this = badge; } -Badge::Badge(const Pokemod* par, const QString& fname, const int _id) : - Object("Badge", par, _id) +Badge::Badge(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Badge", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Badge::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Badge \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Badge \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name not defined"); + pokemod()->validationMsg("Name not defined"); valid = false; } - if (pokemod->getRules()->getMaxLevel() < obey) + if (pokemod()->rules()->maxLevel() < m_obey) { - pokemod->validationMsg("Obey level out of range"); + pokemod()->validationMsg("Obey level out of range"); valid = false; } - if (!QFile(getFace()).exists()) + if (!QFile(face()).exists()) { - pokemod->validationMsg("Cannot find the face sprite"); + pokemod()->validationMsg("Cannot find the face sprite"); valid = false; } - if (!QFile(getBadge()).exists()) + if (!QFile(badge()).exists()) { - pokemod->validationMsg("Cannot find the badge sprite"); + pokemod()->validationMsg("Cannot find the badge sprite"); valid = false; } return valid; } -void Badge::load(const QString& fname, const int _id) throw(Exception) +void Badge::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - ini.getValue("obey", obey, 0); + setId(id); + ini.getValue("name", m_name); + ini.getValue("obey", m_obey, 0); for (int i = 0; i < Pokemod::ST_End_GSC; ++i) { int j; int k; ini.getValue(QString("stats-%1-n").arg(i), j, 1); ini.getValue(QString("stats-%1-d").arg(i), k, 1); - stats[i].set(j, k); + m_stats[i].set(j, k); } for (int i = 0; i < Pokemod::HM_End_All; ++i) - ini.getValue(QString("hm-%1").arg(i), hm[i], false); + ini.getValue(QString("hm-%1").arg(i), m_hm[i], false); } void Badge::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("obey", obey); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("obey", m_obey); for (int i = 0; i < Pokemod::ST_End_GSC; ++i) { - ini.addField(QString("stats-%1-n").arg(i), stats[i].getNum()); - ini.addField(QString("stats-%1-d").arg(i), stats[i].getDenom()); + ini.addField(QString("stats-%1-n").arg(i), m_stats[i].numerator()); + ini.addField(QString("stats-%1-d").arg(i), m_stats[i].denominator()); } for (int i = 0; i < Pokemod::HM_End_All; ++i) - ini.addField(QString("hm-%1").arg(i), hm[i]); - ini.save(QString("%1/badge/%2.pini").arg(pokemod->getPath()).arg(name)); + ini.addField(QString("hm-%1").arg(i), m_hm[i]); + ini.save(QString("%1/badge/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Badge::setName(const QString& n) +void Badge::setName(const QString& name) { - name = n; + m_name = name; } -void Badge::setFace(const QString& f) throw(Exception) +void Badge::setFace(const QString& fileName) throw(Exception) { - QFile file(getFace()); + QFile file(face()); if (file.exists() && !file.remove()) - throw(ReplaceException(className, file.fileName())); - if (!QFile::copy(f, getFace())) - throw(SaveException(className, file.fileName())); + throw(ReplaceException(className(), file.fileName())); + if (!QFile::copy(fileName, face())) + throw(SaveException(className(), file.fileName())); } -void Badge::setBadge(const QString& b) throw(Exception) +void Badge::setBadge(const QString& fileName) throw(Exception) { - QFile file(getBadge()); + QFile file(badge()); if (file.exists() && !file.remove()) - throw(ReplaceException(className, file.fileName())); - if (!QFile::copy(b, getBadge())) - throw(SaveException(className, file.fileName())); -} - -void Badge::setObey(const int o) throw(BoundsException) -{ - if (pokemod->getRules()->getMaxLevel() < o) - throw(BoundsException(className, "obey")); - obey = o; -} - -void Badge::setStat(const int s, const int n, const int d) throw(Exception) -{ - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].set(n, d); + throw(ReplaceException(className(), file.fileName())); + if (!QFile::copy(fileName, badge())) + throw(SaveException(className(), file.fileName())); } -void Badge::setStatNum(const int s, const int n) throw(Exception) +void Badge::setObey(const int obey) throw(BoundsException) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].setNum(n); + if (pokemod()->rules()->maxLevel() < obey) + throw(BoundsException(className(), "obey")); + m_obey = obey; } -void Badge::setStatDenom(const int s, const int d) throw(Exception) +void Badge::setStat(const int stat, const int numerator, const int denominator) throw(Exception) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].setDenom(d); + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) + throw(BoundsException(className(), "stat")); + m_stats[stat].set(numerator, denominator); } -void Badge::setHm(const int h, const bool hb) throw(BoundsException) +void Badge::setHm(const int hm, const bool hmAllowed) throw(BoundsException) { - if (Pokemod::HM_End_All <= h) - throw(BoundsException(className, "hm")); - hm[h] = hb; + if (Pokemod::HM_End_All <= hm) + throw(BoundsException(className(), "hm")); + m_hm[hm] = hmAllowed; } -QString Badge::getName() const +QString Badge::name() const { - return name; + return m_name; } -QString Badge::getFace() const +QString Badge::face() const { - return QString("%1/badge/%2/face.png").arg(pokemod->getPath()).arg(name); + return QString("%1/badge/%2/face.png").arg(pokemod()->path()).arg(m_name); } -QString Badge::getBadge() const +QString Badge::badge() const { - return QString("%1/badge/%2/badge.png").arg(pokemod->getPath()).arg(name); + return QString("%1/badge/%2/badge.png").arg(pokemod()->path()).arg(m_name); } -int Badge::getObey() const +int Badge::obey() const { - return obey; + return m_obey; } -Frac Badge::getStat(const int s) const throw(BoundsException) +Frac Badge::stat(const int stat) const throw(BoundsException) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - return stats[s]; + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) + throw(BoundsException(className(), "stat")); + return m_stats[stat]; } -bool Badge::getHm(const int h) const throw(BoundsException) +bool Badge::hm(const int hm) const throw(BoundsException) { - if (Pokemod::HM_End_All <= h) - throw(BoundsException(className, "hm")); - return hm[h]; + if (Pokemod::HM_End_All <= hm) + throw(BoundsException(className(), "hm")); + return m_hm[hm]; } Badge& Badge::operator=(const Badge& rhs) { if (this == &rhs) return *this; - name = rhs.name; - obey = rhs.obey; + m_name = rhs.m_name; + m_obey = rhs.m_obey; for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - stats[i] = rhs.stats[i]; + m_stats[i] = rhs.m_stats[i]; for (int i = 0; i < Pokemod::HM_End_All; ++i) - hm[i] = rhs.hm[i]; + m_hm[i] = rhs.m_hm[i]; return *this; } diff --git a/pokemod/Badge.h b/pokemod/Badge.h index c5c3bca5..44046688 100644 --- a/pokemod/Badge.h +++ b/pokemod/Badge.h @@ -1,72 +1,67 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Badge.h -// Purpose: Define a badge which can boost some stats and can allow the -// use of special techniques in the overworld -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:27:53 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" #include "Pokemod.h" class Badge : public Object { public: - Badge(const Pokemod* par, const int _id); - Badge(const Pokemod* par, const Badge& b, const int _id); - Badge(const Pokemod* par, const QString& fname, const int _id = -1); + Badge(const Pokemod* pokemod, const int id); + Badge(const Pokemod* pokemod, const Badge& badge, const int id); + Badge(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setFace(const QString& f) throw(Exception); - void setBadge(const QString& b) throw(Exception); - void setObey(const int o) throw(BoundsException); - void setStat(const int s, const int n, const int d) throw(Exception); - void setStatNum(const int s, const int n) throw(Exception); - void setStatDenom(const int s, const int d) throw(Exception); - void setHm(const int h, const bool hb) throw(BoundsException); + void setName(const QString& name); + void setFace(const QString& fileName) throw(Exception); + void setBadge(const QString& fileName) throw(Exception); + void setObey(const int obey) throw(BoundsException); + void setStat(const int stat, const int numerator, const int denominator) throw(Exception); + void setHm(const int hm, const bool hmAllowed) throw(BoundsException); - QString getName() const; - QString getFace() const; - QString getBadge() const; - int getObey() const; - Frac getStat(const int s) const throw(BoundsException); - bool getHm(const int h) const throw(BoundsException); + QString name() const; + QString face() const; + QString badge() const; + int obey() const; + Frac stat(const int stat) const throw(BoundsException); + bool hm(const int hm) const throw(BoundsException); Badge& operator=(const Badge& rhs); private: bool validate() const; - QString name; - int obey; - Frac stats[Pokemod::ST_End_GSC]; - bool hm[Pokemod::HM_End_All]; + QString m_name; + int m_obey; + Frac m_stats[Pokemod::ST_End_GSC]; + bool m_hm[Pokemod::HM_End_All]; }; #endif diff --git a/pokemod/CoinList.cpp b/pokemod/CoinList.cpp index 53002fa0..c0e83a59 100644 --- a/pokemod/CoinList.cpp +++ b/pokemod/CoinList.cpp @@ -1,280 +1,267 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/CoinList.cpp -// Purpose: A specialty store where Pokémon and items can be gotten for -// coins won through gambling -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:16:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> #include <QStringList> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "CoinListObject.h" #include "Item.h" #include "ItemEffect.h" + +// Header include #include "CoinList.h" -CoinList::CoinList(const Pokemod* par, const int _id) : - Object("CoinList", par, _id), - name(""), - value(0) +CoinList::CoinList(const Pokemod* pokemod, const int id) : + Object("CoinList", pokemod, id), + m_name(""), + m_value(0) { } -CoinList::CoinList(const Pokemod* par, const CoinList& c, const int _id) : - Object("CoinList", par, _id) +CoinList::CoinList(const Pokemod* pokemod, const CoinList& coinList, const int id) : + Object("CoinList", pokemod, id) { - *this = c; + *this = coinList; } -CoinList::CoinList(const Pokemod* par, const QString& fname, const int _id) : - Object("CoinList", par, _id) +CoinList::CoinList(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("CoinList", pokemod, id) { - load(fname, _id); + load(fileName, id); } CoinList::~CoinList() { - for (QListIterator<CoinListObject*> i(items); i.hasNext(); ) - delete i.next(); + foreach (CoinListObject* object, m_objects) + delete object; } bool CoinList::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Coin List \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Coin List \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name not defined"); + pokemod()->validationMsg("Name not defined"); valid = false; } bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - if (e->getEffect() == ItemEffect::E_CoinCase) - ok = (e->getVal1() == value); + const ItemEffect* effect = item->effect(j); + if (effect->effect() == ItemEffect::E_CoinCase) + ok = (effect->value1() == m_value); } } if (!ok) { - pokemod->validationMsg("No coin cases which hold the right kind of coin"); + pokemod()->validationMsg("No coin cases which hold the right kind of coin"); valid = false; } - if (getItemCount()) + if (objectCount()) { - QMap<int, int> idChecker; - QMap<int, int> itemChecker; - QMap<int, int> speciesChecker; - for (QListIterator<CoinListObject*> i(items); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + QMap<int, bool> itemChecker; + QMap<int, bool> speciesChecker; + foreach (CoinListObject* object, m_objects) { - if (!i.peekNext()->isValid()) + if (!object->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - if (i.peekNext()->getType() == CoinListObject::Item) - ++itemChecker[i.peekNext()->getObject()]; - else if (i.peekNext()->getType() == CoinListObject::Species) - ++speciesChecker[i.peekNext()->getObject()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + if (idChecker[object->id()]) + pokemod()->validationMsg(QString("Duplicate object with id %1").arg(object->id())); + idChecker[object->id()] = true; + if (object->type() == CoinListObject::Item) { - pokemod->validationMsg(QString("There are %1 objects with id %2").arg(i.value()).arg(i.key())); - valid = false; + if (itemChecker[object->object()]) + pokemod()->validationMsg(QString("Duplicate object with item %1").arg(object->id())); + itemChecker[object->object()] = true; } - } - for (QMapIterator<int, int> i(itemChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + else if (object->type() == CoinListObject::Species) { - pokemod->validationMsg(QString("There are %1 items with the id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<int, int> i(speciesChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 Pokémon with the id %2").arg(i.value()).arg(i.key())); - valid = false; + if (speciesChecker[object->object()]) + pokemod()->validationMsg(QString("Duplicate object with item %1").arg(object->id())); + speciesChecker[object->object()] = true; } } } else { - pokemod->validationMsg("There are no objects"); + pokemod()->validationMsg("There are no objects"); valid = false; } return valid; } -int CoinList::getNewId() const -{ - int i = 0; - for (; (i < getItemCount()) && (getItemIndex(i) != -1); ++i) - ; - return i; -} - -void CoinList::load(const QString& fname, const int _id) throw(Exception) +void CoinList::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - ini.getValue("value", value, 0); - QStringList path = pokemod->getPath().split('/'); + setId(id); + ini.getValue("name", m_name); + ini.getValue("value", m_value, 0); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - items.clear(); + m_objects.clear(); if (fdir.cd("item")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newItem(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newObject(file); } } void CoinList::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("value", value); - ini.save(QString("%1/coinlist/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<CoinListObject*> i(items); i.hasNext(); ) - i.next()->save(name); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("value", m_value); + ini.save(QString("%1/coinlist/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (CoinListObject* object, m_objects) + object->save(m_name); } -void CoinList::setName(const QString& n) +void CoinList::setName(const QString& name) { - name = n; + m_name = name; } -void CoinList::setValue(const int v) throw(Exception) +void CoinList::setValue(const int value) throw(Exception) { - for (int i = 0; (i < pokemod->getItemCount()); ++i) + for (int i = 0; (i < pokemod()->itemCount()); ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()); ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()); ++j) { - const ItemEffect* e = it->getEffect(j); - if ((e->getEffect() == ItemEffect::E_CoinCase) && (e->getVal1() == v)) + const ItemEffect* effect = item->effect(j); + if ((effect->effect() == ItemEffect::E_CoinCase) && (effect->value1() == value)) { - value = v; + m_value = value; return; } } } - throw(Exception(className, "no compatable coin cases")); + throw(Exception(className(), "No compatable coin cases")); } -QString CoinList::getName() const +QString CoinList::name() const { - return name; + return m_name; } -int CoinList::getValue() const +int CoinList::value() const { - return value; + return m_value; } -const CoinListObject* CoinList::getItem(const int i) const throw(IndexException) +const CoinListObject* CoinList::object(const int index) const throw(IndexException) { - if (getItemCount() <= i) - throw(IndexException(className)); - return items.at(i); + if (objectCount() <= index) + throw(IndexException(className())); + return m_objects.at(index); } -CoinListObject* CoinList::getItem(const int i) throw(IndexException) +CoinListObject* CoinList::object(const int index) throw(IndexException) { - if (getItemCount() <= i) - throw(IndexException(className)); - return items[i]; + if (objectCount() <= index) + throw(IndexException(className())); + return m_objects[index]; } -const CoinListObject* CoinList::getItemByID(const int i) const throw(IndexException) +const CoinListObject* CoinList::objectById(const int id) const throw(IndexException) { - return getItem(getItemIndex(i)); + return object(objectIndex(id)); } -CoinListObject* CoinList::getItemByID(const int i) throw(IndexException) +CoinListObject* CoinList::objectById(const int id) throw(IndexException) { - return getItem(getItemIndex(i)); + return object(objectIndex(id)); } -int CoinList::getItemIndex(const int _id) const +int CoinList::objectIndex(const int id) const { - for (int i = 0; i < getItemCount(); ++i) + for (int i = 0; i < objectCount(); ++i) { - if (items[i]->getId() == _id) + if (m_objects[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int CoinList::getItemCount() const +int CoinList::objectCount() const { - return items.size(); + return m_objects.size(); } -CoinListObject* CoinList::newItem() +CoinListObject* CoinList::newObject() { - items.append(new CoinListObject(pokemod, getNewId())); - return items[getItemCount() - 1]; + m_objects.append(new CoinListObject(pokemod(), objectId())); + return m_objects[objectCount() - 1]; } -CoinListObject* CoinList::newItem(const QString& fname) +CoinListObject* CoinList::newObject(const QString& fileName) { - items.append(new CoinListObject(pokemod, fname, getNewId())); - return items[getItemCount() - 1]; + m_objects.append(new CoinListObject(pokemod(), fileName, objectId())); + return m_objects[objectCount() - 1]; } -CoinListObject* CoinList::newItem(const CoinListObject& o) +CoinListObject* CoinList::newObject(const CoinListObject& object) { - items.append(new CoinListObject(pokemod, o, getNewId())); - return items[getItemCount() - 1]; + m_objects.append(new CoinListObject(pokemod(), object, objectId())); + return m_objects[objectCount() - 1]; } -void CoinList::deleteItem(const int i) throw(IndexException) +void CoinList::deleteObject(const int index) throw(IndexException) { - if (getItemCount() <= i) - throw(IndexException(className)); - delete items[i]; - items.removeAt(i); + if (objectCount() <= index) + throw(IndexException(className())); + delete m_objects[index]; + m_objects.removeAt(index); +} + +void CoinList::deleteObjectById(const int id) throw( IndexException ) +{ + deleteObject(objectIndex(id)); +} + +int CoinList::objectId() const +{ + int i = 0; + while ((i < objectCount()) && (objectIndex(i) != INT_MAX)) + ++i; + return i; } CoinList& CoinList::operator=(const CoinList& rhs) { if (this == &rhs) return *this; - name = rhs.name; - items.clear(); - for (int i = 0; i < rhs.getItemCount(); ++i) - items.append(new CoinListObject(pokemod, *rhs.getItem(i), rhs.getItem(i)->getId())); + m_name = rhs.m_name; + m_objects.clear(); + foreach (CoinListObject* object, rhs.m_objects) + m_objects.append(new CoinListObject(pokemod(), *object, object->id())); return *this; } diff --git a/pokemod/CoinList.h b/pokemod/CoinList.h index 09e11aa0..c8e14a80 100644 --- a/pokemod/CoinList.h +++ b/pokemod/CoinList.h @@ -1,76 +1,75 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/CoinList.h -// Purpose: A specialty store where Pokémon and items can be gotten for -// coins won through gambling -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:16:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class CoinListObject; class Pokemod; class CoinList : public Object { public: - CoinList(const Pokemod* par, const int _id); - CoinList(const Pokemod* par, const CoinList& c, const int _id); - CoinList(const Pokemod* par, const QString& fname, const int _id = -1); + CoinList(const Pokemod* pokemod, const int id); + CoinList(const Pokemod* pokemod, const CoinList& coinList, const int id); + CoinList(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~CoinList(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setValue(const int v) throw(Exception); + void setName(const QString& name); + void setValue(const int value) throw(Exception); - QString getName() const; - int getValue() const; + QString name() const; + int value() const; - const CoinListObject* getItem(const int i) const throw(IndexException); - CoinListObject* getItem(const int i) throw(IndexException); - const CoinListObject* getItemByID(const int i) const throw(IndexException); - CoinListObject* getItemByID(const int i) throw(IndexException); - int getItemIndex(const int _id) const; - int getItemCount() const; - CoinListObject* newItem(); - CoinListObject* newItem(const QString& fname); - CoinListObject* newItem(const CoinListObject& o); - void deleteItem(const int i) throw(IndexException); + const CoinListObject* object(const int index) const throw(IndexException); + CoinListObject* object(const int index) throw(IndexException); + const CoinListObject* objectById(const int id) const throw(IndexException); + CoinListObject* objectById(const int id) throw(IndexException); + int objectIndex(const int id) const; + int objectCount() const; + CoinListObject* newObject(); + CoinListObject* newObject(const QString& fileName); + CoinListObject* newObject(const CoinListObject& object); + void deleteObject(const int index) throw(IndexException); + void deleteObjectById(const int id) throw(IndexException); CoinList& operator=(const CoinList& rhs); private: bool validate() const; - int getNewId() const; + int objectId() const; - QString name; - int value; + QString m_name; + int m_value; - QList<CoinListObject*> items; + QList<CoinListObject*> m_objects; }; #endif diff --git a/pokemod/CoinListObject.cpp b/pokemod/CoinListObject.cpp index 143c3db1..4e91136c 100644 --- a/pokemod/CoinListObject.cpp +++ b/pokemod/CoinListObject.cpp @@ -1,162 +1,156 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/CoinListObject.cpp -// Purpose: Define an object that can be bought with gambling winnings -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:21:23 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ #include "Pokemod.h" #include "CoinListObject.h" const QStringList CoinListObject::TypeStr = QStringList() << "Item" << "Pokémon"; -CoinListObject::CoinListObject(const Pokemod* par, const int _id) : - Object("CoinListObject", par, _id), - type(Item), - object(-1), - amount(1), - cost(0) +CoinListObject::CoinListObject(const Pokemod* pokemod, const int id) : + Object("CoinListObject", pokemod, id), + m_type(Item), + m_object(INT_MAX), + m_amount(1), + m_cost(0) { } -CoinListObject::CoinListObject(const Pokemod* par, const CoinListObject& o, const int _id) : - Object("CoinListObject", par, _id) +CoinListObject::CoinListObject(const Pokemod* pokemod, const CoinListObject& object, const int id) : + Object("CoinListObject", pokemod, id) { - *this = o; + *this = object; } -CoinListObject::CoinListObject(const Pokemod* par, const QString& fname, const int _id) : - Object("CoinListObject", par, _id) +CoinListObject::CoinListObject(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("CoinListObject", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool CoinListObject::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Object with id %1---").arg(id), Pokemod::V_Msg); - if (type == Item) + pokemod()->validationMsg(QString("------Object with id %1---").arg(id()), Pokemod::V_Msg); + if (Item == m_type) { - if (pokemod->getItemIndex(object) == -1) + if (pokemod()->itemIndex(m_object) == INT_MAX) { - pokemod->validationMsg("Invalid item"); + pokemod()->validationMsg("Invalid item"); valid = false; } } - else if (type == Species) + else if (Species == m_type) { - if (pokemod->getSpeciesIndex(object) == -1) + if (pokemod()->speciesIndex(m_object) == INT_MAX) { - pokemod->validationMsg("Invalid Species"); + pokemod()->validationMsg("Invalid Species"); valid = false; } } else { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Invalid type"); valid = false; } - if (!amount || ((1 < amount) && (type == Species))) + if (!m_amount || ((1 < m_amount) && (Species == m_type))) { - pokemod->validationMsg("Invalid amount"); + pokemod()->validationMsg("Invalid amount"); valid = false; } return valid; } -void CoinListObject::load(const QString& fname, const int _id) throw(Exception) +void CoinListObject::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("type", type, Item); - ini.getValue("object", object); - ini.getValue("amount", amount, 1); - ini.getValue("cost", cost, 0); + setId(id); + ini.getValue("type", m_type, Item); + ini.getValue("object", m_object); + ini.getValue("amount", m_amount, 1); + ini.getValue("cost", m_cost, 0); } void CoinListObject::save(const QString& coinList) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("type", type); - ini.addField("object", object); - ini.addField("amount", amount); - ini.addField("cost", cost); - ini.save(QString("%1/coinlist/%2/item/%3.pini").arg(pokemod->getPath()).arg(coinList).arg(id)); + ini.addField("id", id()); + ini.addField("type", m_type); + ini.addField("object", m_object); + ini.addField("amount", m_amount); + ini.addField("cost", m_cost); + ini.save(QString("%1/coinlist/%2/item/%3.pini").arg(pokemod()->path()).arg(coinList).arg(id())); } -void CoinListObject::setType(const int t) throw(BoundsException) +void CoinListObject::setType(const int type) throw(BoundsException) { - if (End <= t) - throw(BoundsException(className, "type")); - type = t; - object = -1; + if (End <= type) + throw(BoundsException(className(), "type")); + m_type = type; + m_object = INT_MAX; } -void CoinListObject::setObject(const int o) throw(BoundsException) +void CoinListObject::setObject(const int object) throw(BoundsException) { - if (((type == Item) && (pokemod->getItemIndex(o) == -1)) || ((type == Species) && (pokemod->getSpeciesIndex(o) == -1))) - throw(BoundsException(className, "object")); - object = o; + if (((Item == m_type) && (pokemod()->itemIndex(object) == INT_MAX)) || ((Species == m_type) && (pokemod()->speciesIndex(object) == INT_MAX))) + throw(BoundsException(className(), "object")); + m_object = object; } -void CoinListObject::setAmount(const int a) throw(BoundsException) +void CoinListObject::setAmount(const int amount) throw(BoundsException) { - if (!a) - throw(BoundsException(className, "amount")); - amount = a; + if (!amount || ((Species == m_type) && (1 < amount))) + throw(BoundsException(className(), "amount")); + m_amount = amount; } -void CoinListObject::setCost(const int c) +void CoinListObject::setCost(const int cost) { - cost = c; + m_cost = cost; } -int CoinListObject::getType() const +int CoinListObject::type() const { - return type; + return m_type; } -int CoinListObject::getObject() const +int CoinListObject::object() const { - return object; + return m_object; } -int CoinListObject::getAmount() const +int CoinListObject::amount() const { - return amount; + return m_amount; } -int CoinListObject::getCost() const +int CoinListObject::cost() const { - return cost; + return m_cost; } CoinListObject& CoinListObject::operator=(const CoinListObject& rhs) { if (this == &rhs) return *this; - type = rhs.type; - object = rhs.object; - amount = rhs.amount; - cost = rhs.cost; + m_type = rhs.m_type; + m_object = rhs.m_object; + m_amount = rhs.m_amount; + m_cost = rhs.m_cost; return *this; } diff --git a/pokemod/CoinListObject.h b/pokemod/CoinListObject.h index e3159cf2..ce5f1fd4 100644 --- a/pokemod/CoinListObject.h +++ b/pokemod/CoinListObject.h @@ -1,35 +1,34 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/CoinListObject.h -// Purpose: Define an object that can be bought with gambling winnings -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:21:23 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// QT includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class CoinListObject : public Object @@ -43,31 +42,31 @@ class CoinListObject : public Object }; static const QStringList TypeStr; - CoinListObject(const Pokemod* par, const int _id); - CoinListObject(const Pokemod* par, const CoinListObject& o, const int _id); - CoinListObject(const Pokemod* par, const QString& fname, const int _id = -1); + CoinListObject(const Pokemod* pokemod, const int id); + CoinListObject(const Pokemod* pokemod, const CoinListObject& object, const int id); + CoinListObject(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& coinList) const throw(Exception); - void setType(const int t) throw(BoundsException); - void setObject(const int o) throw(BoundsException); - void setAmount(const int a) throw(BoundsException); - void setCost(const int c); + void setType(const int type) throw(BoundsException); + void setObject(const int object) throw(BoundsException); + void setAmount(const int amount) throw(BoundsException); + void setCost(const int cost); - int getType() const; - int getObject() const; - int getAmount() const; - int getCost() const; + int type() const; + int object() const; + int amount() const; + int cost() const; - CoinListObject& operator=(const CoinListObject& o); + CoinListObject& operator=(const CoinListObject& rhs); private: bool validate() const; - int type; - int object; - int amount; - int cost; + int m_type; + int m_object; + int m_amount; + int m_cost; }; #endif diff --git a/pokemod/Dialog.cpp b/pokemod/Dialog.cpp index e0a7d3d2..aae66688 100644 --- a/pokemod/Dialog.cpp +++ b/pokemod/Dialog.cpp @@ -1,26 +1,21 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Dialog.cpp -// Purpose: Define a dialog in a PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:05:56 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ -#include "Pokemod.h" +// Pokemod includes #include "Item.h" #include "ItemEffect.h" #include "Map.h" @@ -28,52 +23,55 @@ #include "MapTrainer.h" #include "MapWarp.h" #include "Move.h" +#include "Pokemod.h" #include "Species.h" + +// Header include #include "Dialog.h" const QStringList Dialog::CommandStr = QStringList() << "Flip Flag" << "Set Flag" << "Unset Flag" << "Randomize Flag" << "Test Flag" << "Dialog" << "Yes/No" << "Item Shop" << "Give Item" << "Take Item" << "Check Item" << "Coin List" << "Teach Move" << "Delete Move" << "Give Pokemon" << "Take Pokemon" << "Show Pokemon" << "View Pokemon" << "Give Money" << "Take Money" << "Move Effect" << "Turn Effect" << "Check Direction" << "Check Roster" << "Check Levels" << "Check Species" << "Check Held Items" << "Check Money" << "Trade" << "Daycare" << "Battle" << "Badge" << "Warp" << "Name" << "Music" << "Sound Effect" << "Timer" << "Map Sign" << "Wild Scope" << "Safari" << "Heal Party" << "Refresh" << "Clear" << "Pause" << "New Line" << "Exit" << "Menu"; const QStringList Dialog::CommandAbbrStr = QStringList() << "FF" << "SF" << "UF" << "RF" << "TF" << "D" << "YN" << "ItS" << "GIt" << "TIt" << "CIt" << "CL" << "TMv" << "DMv" << "GPk" << "TPk" << "SPk" << "VPk" << "G$" << "T$" << "MvEf" << "TEf" << "CD" << "CR" << "CLv" << "CS" << "CHIt" << "C$" << "T" << "Dc" << "Bat" << "Bdg" << "W" << "N" << "Ms" << "SFX" << "Tmr" << "MS" << "WS" << "S" << "HP" << "R" << "C" << "P" << "NL" << "X" << "M"; const QList<int> Dialog::CommandNumArgs = QList<int>() << 1 << 1 << 1 << 1 << 3 << 2 << 2 << 1 << 4 << 4 << 4 << 1 << 5 << 3 << 7 << 4 << 1 << 4 << 1 << 4 << 6 << 3 << 6 << 5 << 5 << 4 << 4 << 5 << 6 << 1 << 2 << 1 << 2 << 1 << 2 << 1 << 3 << 1 << 1 << 3 << 0 << 0 << 0 << 0 << 0 << 0; -Dialog::Dialog(const Pokemod* par, const int _id) : - Object("Dialog", par, _id), - dialog("") +Dialog::Dialog(const Pokemod* pokemod, const int id) : + Object("Dialog", pokemod, id), + m_dialog("") { } -Dialog::Dialog(const Pokemod* par, const Dialog& d, const int _id) : - Object("Dialog", par, _id) +Dialog::Dialog(const Pokemod* pokemod, const Dialog& dialog, const int id) : + Object("Dialog", pokemod, id) { - *this = d; + *this = dialog; } -Dialog::Dialog(const Pokemod* par, const QString& fname, const int _id) : - Object("Dialog", par, _id) +Dialog::Dialog(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Dialog", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Dialog::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Dialog with id %1---").arg(id), Pokemod::V_Msg); - if (dialog == "") + pokemod()->validationMsg(QString("---Dialog with id %1---").arg(id()), Pokemod::V_Msg); + if (m_dialog == "") { - pokemod->validationMsg("Dialog is empty"); + pokemod()->validationMsg("Dialog is empty"); valid = false; } - if (dialog.count('%') & 1) + if (m_dialog.count('%') & 1) { - pokemod->validationMsg("Command delimiter mismatch"); + pokemod()->validationMsg("Command delimiter mismatch"); valid = false; } else { int curCmd = End; int numArgs = 0; - for (int i = 0; i < dialog.length(); ++i) + for (int i = 0; i < m_dialog.length(); ++i) { - switch (dialog.at(i).toAscii()) + switch (m_dialog.at(i).toAscii()) { case '%': switch (curCmd) @@ -81,26 +79,26 @@ bool Dialog::validate() const case FlipFlag ... Exit: if (numArgs != CommandNumArgs[curCmd]) { - pokemod->validationMsg(QString("Invalid number of arguments for \"%1\". %2 given when %3 needed").arg(CommandStr[curCmd]).arg(numArgs).arg(CommandNumArgs[curCmd])); + pokemod()->validationMsg(QString("Invalid number of arguments for \"%1\". %2 given when %3 needed").arg(CommandStr[curCmd]).arg(numArgs).arg(CommandNumArgs[curCmd])); valid = false; } break; case Menu: if (!(numArgs & 1)) { - pokemod->validationMsg("Invalid number of arguments for Menu"); + pokemod()->validationMsg("Invalid number of arguments for Menu"); valid = false; } break; case End: QString curCmdStr; - for (; (dialog.at(i) != '%') && (dialog.at(i) != '#'); ++i) - curCmdStr += dialog.at(i); - if (((curCmd = CommandAbbrStr.indexOf(curCmdStr))) == -1) + for (; (m_dialog.at(i) != '%') && (m_dialog.at(i) != '#'); ++i) + curCmdStr += m_dialog.at(i); + if (((curCmd = CommandAbbrStr.indexOf(curCmdStr))) == INT_MAX) { if (curCmdStr != "") { - pokemod->validationMsg(QString("Invalid command \"%1\"").arg(curCmdStr)); + pokemod()->validationMsg(QString("Invalid command \"%1\"").arg(curCmdStr)); valid = false; } curCmd = End; @@ -113,8 +111,8 @@ bool Dialog::validate() const if (curCmd != End) { QString arg; - for (; (dialog.at(i) != '%') && (dialog.at(i) != '#'); ++i) - arg += dialog.at(i); + for (; (m_dialog.at(i) != '%') && (m_dialog.at(i) != '#'); ++i) + arg += m_dialog.at(i); bool ok; int temp = arg.toInt(&ok); int invError = 0; @@ -130,7 +128,7 @@ bool Dialog::validate() const { if (!ok) { - pokemod->validationMsg(QString("Bad flag in \"%1\"").arg(CommandStr[curCmd])); + pokemod()->validationMsg(QString("Bad flag in \"%1\"").arg(CommandStr[curCmd])); valid = false; } } @@ -145,13 +143,13 @@ bool Dialog::validate() const case 2: if (!ok) { - pokemod->validationMsg("Bad flag in \"Test Flag\""); + pokemod()->validationMsg("Bad flag in \"Test Flag\""); valid = false; } break; case 3: case 4: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; } break; @@ -163,7 +161,7 @@ bool Dialog::validate() const } else if (numArgs == 2) { - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = 2; } break; @@ -177,14 +175,14 @@ bool Dialog::validate() const break; case 2: case 3: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; } break; case ItemShop: if (numArgs == 1) { - if (!ok || (pokemod->getStoreIndex(temp) == -1)) + if (!ok || (pokemod()->storeIndex(temp) == INT_MAX)) invError = 1; } break; @@ -198,12 +196,12 @@ bool Dialog::validate() const invError = 1; break; case 2: - if (!ok || (pokemod->getItemIndex(temp) == -1)) + if (!ok || (pokemod()->itemIndex(temp) == INT_MAX)) invError = 2; break; case 3: case 4: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -211,7 +209,7 @@ bool Dialog::validate() const case CoinList: if (numArgs == 1) { - if (!ok || (pokemod->getCoinListIndex(temp) == -1)) + if (!ok || (pokemod()->coinListIndex(temp) == INT_MAX)) invError = 1; } break; @@ -223,13 +221,13 @@ bool Dialog::validate() const invError = 1; break; case 2: - if (!ok || (pokemod->getMoveIndex(temp) == -1)) + if (!ok || (pokemod()->moveIndex(temp) == INT_MAX)) invError = 2; break; case 3: case 4: case 5: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -246,12 +244,12 @@ bool Dialog::validate() const invError = 2; break; case 3: - if (!ok || (pokemod->getMoveIndex(temp) == -1)) + if (!ok || (pokemod()->moveIndex(temp) == INT_MAX)) invError = 3; break; case 4: case 5: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -264,7 +262,7 @@ bool Dialog::validate() const invError = 1; break; case 2: - if (!ok || (pokemod->getSpeciesIndex(temp) ==-1)) + if (!ok || (pokemod()->speciesIndex(temp) ==INT_MAX)) invError = 2; break; case 3: @@ -274,9 +272,9 @@ bool Dialog::validate() const case 4: if (ok) { - if (pokemod->getRules()->getMaxLevel() < temp) + if (pokemod()->rules()->maxLevel() < temp) { - pokemod->validationMsg("Higher level than allowed in \"Give Pokémon\""); + pokemod()->validationMsg("Higher level than allowed in \"Give Pokémon\""); valid = false; } } @@ -289,7 +287,7 @@ bool Dialog::validate() const break; case 6: case 7: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -304,12 +302,12 @@ bool Dialog::validate() const invError = 1; break; case 2: - if (!ok || (pokemod->getSpeciesIndex(temp) == -1)) + if (!ok || (pokemod()->speciesIndex(temp) == INT_MAX)) invError = 2; break; case 3: case 4: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -317,7 +315,7 @@ bool Dialog::validate() const case ShowPokemon: if (numArgs == 1) { - if (!ok || (pokemod->getSpeciesIndex(temp) == -1)) + if (!ok || (pokemod()->speciesIndex(temp) == INT_MAX)) invError = 1; } break; @@ -326,9 +324,9 @@ bool Dialog::validate() const { if (ok) { - if (pokemod->getRules()->getMaxMoney() < temp) + if (pokemod()->rules()->maxMoney() < temp) { - pokemod->validationMsg("More money given than can be held in \"Give Money\"", Pokemod::V_Warn); + pokemod()->validationMsg("More money given than can be held in \"Give Money\"", Pokemod::V_Warn); valid = false; } } @@ -346,9 +344,9 @@ bool Dialog::validate() const case 2: if (ok) { - if (pokemod->getRules()->getMaxMoney() < temp) + if (pokemod()->rules()->maxMoney() < temp) { - pokemod->validationMsg("More money taken than can be held in \"Take Money\""); + pokemod()->validationMsg("More money taken than can be held in \"Take Money\""); valid = false; } } @@ -357,7 +355,7 @@ bool Dialog::validate() const break; case 3: case 4: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -371,19 +369,19 @@ bool Dialog::validate() const invError = 1; break; case 2: - if (!ok || (pokemod->getMapIndex(temp) == -1)) + if (!ok || (pokemod()->mapIndex(temp) == INT_MAX)) invError = 2; else - map = pokemod->getMapByID(temp); + map = pokemod()->mapById(temp); break; case 3: if (map) { - if (!ok || (map->getEffectIndex(temp) == -1)) + if (!ok || (map->effectIndex(temp) == INT_MAX)) invError = 3; } - else if ((arg != "Player") && (arg != "-1")) - pokemod->validationMsg(QString("Unable to validate argument #3 in \"%1\"").arg(CommandStr[curCmd])); + else if ((arg != "Player") && (arg != "INT_MAX")) + pokemod()->validationMsg(QString("Unable to validate argument #3 in \"%1\"").arg(CommandStr[curCmd])); break; case 4: if ((arg != "Up") && (arg != "Down") && (arg != "Left") && (arg != "Right") && ((arg != "Random") || (curCmd == CheckDirection)) && (arg != "0") && (arg != "1") && (arg != "2") && (arg != "3") && ((arg != "4") || (curCmd == CheckDirection))) @@ -391,7 +389,7 @@ bool Dialog::validate() const break; case 5: case 6: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -400,19 +398,19 @@ bool Dialog::validate() const switch (numArgs) { case 1: - if (!ok || (pokemod->getMapIndex(temp) == -1)) + if (!ok || (pokemod()->mapIndex(temp) == INT_MAX)) invError = 1; else - map = pokemod->getMapByID(temp); + map = pokemod()->mapById(temp); break; case 2: if (map) { - if (!ok || (map->getEffectIndex(temp) == -1)) + if (!ok || (map->effectIndex(temp) == INT_MAX)) invError = 2; } - else if ((arg != "Player") && (arg != "-1")) - pokemod->validationMsg("Unable to validate argument #2 in \"Turn Effect\""); + else if ((arg != "Player") && (arg != "INT_MAX")) + pokemod()->validationMsg("Unable to validate argument #2 in \"Turn Effect\""); map = NULL; break; case 3: @@ -437,9 +435,9 @@ bool Dialog::validate() const case 3: if (ok) { - if (((curCmd == CheckRoster) ? pokemod->getRules()->getMaxParty() : ((curCmd == CheckLevels) ? pokemod->getRules()->getMaxLevel() : pokemod->getRules()->getMaxMoney())) < temp) + if (((curCmd == CheckRoster) ? pokemod()->rules()->maxParty() : ((curCmd == CheckLevels) ? pokemod()->rules()->maxLevel() : pokemod()->rules()->maxMoney())) < temp) { - pokemod->validationMsg(QString("More %1 than can be carried in \"%2\"").arg((curCmd == CheckRoster) ? "party members" : ((curCmd == CheckLevels) ? "level" : "money")).arg(CommandStr[curCmd])); + pokemod()->validationMsg(QString("More %1 than can be carried in \"%2\"").arg((curCmd == CheckRoster) ? "party members" : ((curCmd == CheckLevels) ? "level" : "money")).arg(CommandStr[curCmd])); valid = false; } } @@ -448,7 +446,7 @@ bool Dialog::validate() const break; case 4: case 5: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -463,7 +461,7 @@ bool Dialog::validate() const case 2: case 3: case 4: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; } break; @@ -476,7 +474,7 @@ bool Dialog::validate() const break; case 2: case 3: - if (!ok || (pokemod->getSpeciesIndex(temp) == -1)) + if (!ok || (pokemod()->speciesIndex(temp) == INT_MAX)) invError = numArgs; case 4: if (!ok) @@ -484,7 +482,7 @@ bool Dialog::validate() const break; case 5: case 6: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = numArgs; break; } @@ -499,47 +497,47 @@ bool Dialog::validate() const case Battle: if (numArgs == 1) { - if (!ok || (pokemod->getMapIndex(temp) == -1)) + if (!ok || (pokemod()->mapIndex(temp) == INT_MAX)) invError = 1; else - map = pokemod->getMapByID(temp); + map = pokemod()->mapById(temp); } else if (numArgs == 2) { if (map) { - if (!ok || (map->getTrainerIndex(temp) == -1)) + if (!ok || (map->trainerIndex(temp) == INT_MAX)) invError = 2; } else - pokemod->validationMsg("Unable to validate argument #2 in \"Battle\""); + pokemod()->validationMsg("Unable to validate argument #2 in \"Battle\""); map = NULL; } break; case Badge: if (numArgs == 1) { - if (!ok || (pokemod->getBadgeIndex(temp) == -1)) + if (!ok || (pokemod()->badgeIndex(temp) == INT_MAX)) invError = 1; } break; case Warp: if (numArgs == 1) { - if (!ok || (pokemod->getMapIndex(temp) == -1)) + if (!ok || (pokemod()->mapIndex(temp) == INT_MAX)) invError = 1; else - map = pokemod->getMapByID(temp); + map = pokemod()->mapById(temp); } else if (numArgs == 2) { if (map) { - if (!ok || (map->getWarpIndex(temp) == -1)) + if (!ok || (map->warpIndex(temp) == INT_MAX)) invError = 2; } else - pokemod->validationMsg("Unable to validate argument #2 in \"Warp\""); + pokemod()->validationMsg("Unable to validate argument #2 in \"Warp\""); map = NULL; } break; @@ -554,14 +552,14 @@ bool Dialog::validate() const case Music: if (numArgs == 1) { - if (!QFile(QString("%1/music/%2").arg(pokemod->getPath()).arg(arg)).exists()) + if (!QFile(QString("%1/music/%2").arg(pokemod()->path()).arg(arg)).exists()) invError = 1; } break; case SoundEffect: if (numArgs == 1) { - if (!QFile(QString("%1/sound/%2").arg(pokemod->getPath()).arg(arg)).exists()) + if (!QFile(QString("%1/sound/%2").arg(pokemod()->path()).arg(arg)).exists()) invError = 1; } else if (numArgs == 2) @@ -582,7 +580,7 @@ bool Dialog::validate() const invError = 2; break; case 3: - if (!ok || (pokemod->getDialogIndex(temp) == -1)) + if (!ok || (pokemod()->dialogIndex(temp) == INT_MAX)) invError = 3; break; } @@ -598,18 +596,18 @@ bool Dialog::validate() const switch (numArgs) { case 1: - if (ok && (pokemod->getItemIndex(temp) != -1)) + if (ok && (pokemod()->itemIndex(temp) != INT_MAX)) { - const Item* item = pokemod->getItemByID(temp); + const Item* item = pokemod()->itemById(temp); bool temp = false; - for (int i = 0; (i < item->getEffectCount()) || !temp; ++i) + for (int i = 0; (i < item->effectCount()) || !temp; ++i) { - if (item->getEffect(i)->getEffect() == ItemEffect::E_Ball) + if (item->effect(i)->effect() == ItemEffect::E_Ball) temp = true; } if (!temp) { - pokemod->validationMsg("Item in argument #1 in \"Safari\" isn\'t a PokéBall"); + pokemod()->validationMsg("Item in argument #1 in \"Safari\" isn\'t a PokéBall"); valid = false; } } @@ -621,7 +619,7 @@ bool Dialog::validate() const invError = 2; break; case 3: - if (!ok || (pokemod->getRules()->getMaxParty() < temp)) + if (!ok || (pokemod()->rules()->maxParty() < temp)) invError = 3; break; } @@ -636,7 +634,7 @@ bool Dialog::validate() const { if (ok) { - if (pokemod->getDialogIndex(temp) == -1) + if (pokemod()->dialogIndex(temp) == INT_MAX) invError = numArgs; } else @@ -648,7 +646,7 @@ bool Dialog::validate() const } if (invError) { - pokemod->validationMsg(QString("Invalid argument #%1 in \"%2\"").arg(invError).arg(CommandStr[curCmd])); + pokemod()->validationMsg(QString("Invalid argument #%1 in \"%2\"").arg(invError).arg(CommandStr[curCmd])); valid = false; } } @@ -659,45 +657,44 @@ bool Dialog::validate() const return valid; } -void Dialog::load(const QString& fname, const int _id) throw(Exception) +void Dialog::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue(className, dialog); + setId(id); + ini.getValue("dialog", m_dialog); } void Dialog::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField(className, dialog); - ini.save(QString("%1/dialog/%2.pini").arg(pokemod->getPath()).arg(id)); + ini.addField("id", id()); + ini.addField("dialog", m_dialog); + ini.save(QString("%1/dialog/%2.pini").arg(pokemod()->path()).arg(id())); } -void Dialog::setDialog(const QString& d) +void Dialog::setDialog(const QString& dialog) { - dialog = d; + m_dialog = dialog; } -QString Dialog::getDialog() const +QString Dialog::dialog() const { - return dialog; + return m_dialog; } -void Dialog::insertDialogCommand(const QString& cmd, const int pos) throw(BoundsException) +void Dialog::insertCommand(const int position, const QString& command) throw(BoundsException) { - if (dialog.length() < pos) - throw(BoundsException(className , "command")); - dialog.insert(pos, cmd); + if (m_dialog.length() < position) + throw(BoundsException(className(), "command")); + m_dialog.insert(position, command); } Dialog& Dialog::operator=(const Dialog& rhs) { if (this == &rhs) return *this; - dialog = rhs.dialog; + m_dialog = rhs.m_dialog; return *this; } diff --git a/pokemod/Dialog.h b/pokemod/Dialog.h index d3ee81f3..a8bf3ebe 100644 --- a/pokemod/Dialog.h +++ b/pokemod/Dialog.h @@ -1,36 +1,35 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Dialog.h -// Purpose: Define a dialog in a PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:05:56 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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_DIALOG__ #define __POKEMOD_DIALOG__ +// Qt includes #include <QList> #include <QString> #include <QStringList> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class Dialog : public Object @@ -92,24 +91,24 @@ class Dialog : public Object static const QStringList CommandAbbrStr; static const QList<int> CommandNumArgs; - Dialog(const Pokemod* par, const int _id); - Dialog(const Pokemod* par, const Dialog& d, const int _id); - Dialog(const Pokemod* par, const QString& fname, const int _id = -1); + Dialog(const Pokemod* pokemod, const int id); + Dialog(const Pokemod* pokemod, const Dialog& dialog, const int id); + Dialog(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setDialog(const QString& d); + void setDialog(const QString& dialog); - QString getDialog() const; + QString dialog() const; - void insertDialogCommand(const QString& cmd, const int pos) throw(BoundsException); + void insertCommand(const int position, const QString& command) throw(BoundsException); Dialog& operator=(const Dialog& rhs); private: bool validate() const; - QString dialog; + QString m_dialog; }; #endif diff --git a/pokemod/EggGroup.cpp b/pokemod/EggGroup.cpp index 17c90e87..4d8a6391 100644 --- a/pokemod/EggGroup.cpp +++ b/pokemod/EggGroup.cpp @@ -1,90 +1,84 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/EggGroup.cpp -// Purpose: Define a breeding gourp -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:05:05 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ #include "Pokemod.h" #include "EggGroup.h" -EggGroup::EggGroup(const Pokemod* par, const int _id) : - Object("EggGroup", par, _id), - name("") +EggGroup::EggGroup(const Pokemod* pokemod, const int id) : + Object("EggGroup", pokemod, id), + m_name("") { } -EggGroup::EggGroup(const Pokemod* par, const EggGroup& e, const int _id) : - Object("EggGroup", par, _id) +EggGroup::EggGroup(const Pokemod* pokemod, const EggGroup& eggGroup, const int id) : + Object("EggGroup", pokemod, id) { - *this = e; + *this = eggGroup; } -EggGroup::EggGroup(const Pokemod* par, const QString& fname, const int _id) : - Object("EggGroup", par, _id) +EggGroup::EggGroup(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("EggGroup", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool EggGroup::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Egg Group \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Egg Group \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } return valid; } -void EggGroup::load(const QString& fname, const int _id) throw(Exception) +void EggGroup::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); + setId(id); + ini.getValue("name", m_name); } void EggGroup::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.save(QString("%1/egggroup/%2.pini").arg(pokemod->getPath()).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.save(QString("%1/egggroup/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void EggGroup::setName(const QString& n) +void EggGroup::setName(const QString& name) { - name = n; + m_name = name; } -QString EggGroup::getName() const +QString EggGroup::name() const { - return name; + return m_name; } EggGroup& EggGroup::operator=(const EggGroup& rhs) { if (this == &rhs) return *this; - name = rhs.name; + m_name = rhs.m_name; return *this; } diff --git a/pokemod/EggGroup.h b/pokemod/EggGroup.h index 2f839b5e..d95c80d1 100644 --- a/pokemod/EggGroup.h +++ b/pokemod/EggGroup.h @@ -1,55 +1,54 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/EggGroup.h -// Purpose: Define a breeding group -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:05:05 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class EggGroup : public Object { public: - EggGroup(const Pokemod* par, const int _id); - EggGroup(const Pokemod* par, const EggGroup& e, const int _id); - EggGroup(const Pokemod* par, const QString& fname, const int _id = -1); + EggGroup(const Pokemod* pokemod, const int id); + EggGroup(const Pokemod* pokemod, const EggGroup& eggGroup, const int id); + EggGroup(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); + void setName(const QString& name); - QString getName() const; + QString name() const; EggGroup& operator=(const EggGroup& rhs); private: bool validate() const; - QString name; + QString m_name; }; #endif diff --git a/pokemod/Item.cpp b/pokemod/Item.cpp index f2a594d6..91d0ef3f 100644 --- a/pokemod/Item.cpp +++ b/pokemod/Item.cpp @@ -1,284 +1,279 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Item.cpp -// Purpose: Define an item -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:16:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> #include <QStringList> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "ItemEffect.h" + +// Header include #include "Item.h" -Item::Item(const Pokemod* par, const int _id) : - Object("Item", par, _id), - name(""), - sellable(false), - type(-1), - price(0), - description("") +Item::Item(const Pokemod* pokemod, const int id) : + Object("Item", pokemod, id), + m_name(""), + m_sellable(false), + m_type(INT_MAX), + m_price(0), + m_description("") { } -Item::Item(const Pokemod* par, const Item& i, const int _id) : - Object("Item", par, _id) +Item::Item(const Pokemod* pokemod, const Item& item, const int id) : + Object("Item", pokemod, id) { - *this = i; + *this = item; } -Item::Item(const Pokemod* par, const QString& fname, const int _id) : - Object("Item", par, _id) +Item::Item(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Item", pokemod, id) { - load(fname, _id); + load(fileName, id); } Item::~Item() { - for (QListIterator<ItemEffect*> i(effects); i.hasNext(); ) - delete i.next(); + foreach (ItemEffect* effect, m_effects) + delete effect; } bool Item::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Item \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Item \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (pokemod->getItemTypeIndex(type) == -1) + if (pokemod()->itemTypeIndex(m_type) == INT_MAX) { - pokemod->validationMsg("Invalid item type"); + pokemod()->validationMsg("Invalid item type"); valid = false; } - if (pokemod->getRules()->getMaxMoney() < price) + if (pokemod()->rules()->maxMoney() < m_price) { - pokemod->validationMsg("Invalid price"); + pokemod()->validationMsg("Invalid price"); valid = false; } - if (getEffectCount()) + if (effectCount()) { - QMap<int, int> idChecker; - for (QListIterator<ItemEffect*> i(effects); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + foreach (ItemEffect* effect, m_effects) { - if (!i.peekNext()->isValid()) + if (!effect->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[effect->id()]) + pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); + idChecker[effect->id()] = true; } } else { - pokemod->validationMsg("There are no effects"); + pokemod()->validationMsg("There are no effects"); valid = false; } return valid; } -int Item::getNewId() const -{ - int i = 0; - for (; (i < getEffectCount()) && (getEffectIndex(i) != -1); ++i) - ; - return i; -} - -void Item::load(const QString& fname, const int _id) throw(Exception) +void Item::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - ini.getValue("sellable", sellable, false); - ini.getValue("type", type); - ini.getValue("price", price, 0); - ini.getValue("description", description); - QStringList path = pokemod->getPath().split('/'); + setId(id); + ini.getValue("name", m_name); + ini.getValue("sellable", m_sellable, false); + ini.getValue("type", m_type); + ini.getValue("price", m_price, 0); + ini.getValue("description", m_description); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - effects.clear(); + m_effects.clear(); if (fdir.cd("effect")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEffect(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newEffect(file); } } void Item::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("sellable", sellable); - ini.addField("type", type); - ini.addField("price", price); - ini.addField("description", description); - ini.save(QString("%1/item/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<ItemEffect*> i(effects); i.hasNext(); ) - i.next()->save(name); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("sellable", m_sellable); + ini.addField("type", m_type); + ini.addField("price", m_price); + ini.addField("description", m_description); + ini.save(QString("%1/item/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (ItemEffect* effect, m_effects) + effect->save(m_name); } -void Item::setName(const QString& n) +void Item::setName(const QString& name) { - name = n; + m_name = name; } -void Item::setSellable(const bool s) +void Item::setSellable(const bool sellable) { - sellable = s; + m_sellable = sellable; } -void Item::setType(const int t) throw(BoundsException) +void Item::setType(const int type) throw(BoundsException) { - if (pokemod->getItemTypeIndex(t) == -1) - throw(BoundsException(className, "type")); - type = t; + if (pokemod()->itemTypeIndex(type) == INT_MAX) + throw(BoundsException(className(), "type")); + m_type = type; } -void Item::setPrice(const int p) throw(BoundsException) +void Item::setPrice(const int price) throw(BoundsException) { - if (pokemod->getRules()->getMaxMoney() < p) - throw(BoundsException(className, "price")); - price = p; + if (pokemod()->rules()->maxMoney() < price) + throw(BoundsException(className(), "price")); + m_price = price; } -void Item::setDescription(const QString& d) +void Item::setDescription(const QString& description) { - description = d; + m_description = description; } -QString Item::getName() const +QString Item::name() const { - return name; + return m_name; } -bool Item::getSellable() const +bool Item::sellable() const { - return sellable; + return m_sellable; } -int Item::getType() const +int Item::type() const { - return type; + return m_type; } -int Item::getPrice() const +int Item::price() const { - return price; + return m_price; } -QString Item::getDescription() const +QString Item::description() const { - return description; + return m_description; } -const ItemEffect* Item::getEffect(const int i) const throw(IndexException) +const ItemEffect* Item::effect(const int index) const throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects.at(i); + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects.at(index); } -ItemEffect* Item::getEffectByID(const int i) throw(IndexException) +ItemEffect* Item::effect(const int index) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects[i]; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects[index]; } -const ItemEffect* Item::getEffectByID(const int i) const throw(IndexException) +const ItemEffect* Item::effectById(const int id) const throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(id)); } -ItemEffect* Item::getEffect(const int i) throw(IndexException) +ItemEffect* Item::effectById(const int id) throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(id)); } -int Item::getEffectIndex(const int _id) const +int Item::effectIndex(const int id) const { - for (int i = 0; i < getEffectCount(); ++i) + for (int i = 0; i < effectCount(); ++i) { - if (effects[i]->getId() == _id) + if (m_effects[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Item::getEffectCount() const +int Item::effectCount() const { - return effects.size(); + return m_effects.size(); } ItemEffect* Item::newEffect() { - effects.append(new ItemEffect(pokemod, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new ItemEffect(pokemod(), effectId())); + return m_effects[effectCount() - 1]; } -ItemEffect* Item::newEffect(const QString& fname) +ItemEffect* Item::newEffect(const QString& fileName) { - effects.append(new ItemEffect(pokemod, fname, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new ItemEffect(pokemod(), fileName, effectId())); + return m_effects[effectCount() - 1]; } -ItemEffect* Item::newEffect(const ItemEffect& e) +ItemEffect* Item::newEffect(const ItemEffect& effect) { - effects.append(new ItemEffect(pokemod, e, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new ItemEffect(pokemod(), effect, effectId())); + return m_effects[effectCount() - 1]; } -void Item::deleteEffect(const int i) throw(IndexException) +void Item::deleteEffect(const int index) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - delete effects[i]; - effects.removeAt(i); + if (effectCount() <= index) + throw(IndexException(className())); + delete m_effects[index]; + m_effects.removeAt(index); +} + +void Item::deleteEffectById(const int id) throw(IndexException) +{ + deleteEffect(effectIndex(id)); +} + +int Item::effectId() const +{ + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; } Item& Item::operator=(const Item& rhs) { if (this == &rhs) return *this; - name = rhs.name; - sellable = rhs.sellable; - type = rhs.type; - price = rhs.price; - description = rhs.description; - effects.clear(); - for (int i = 0; i < rhs.getEffectCount(); ++i) - effects.append(new ItemEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); + m_name = rhs.m_name; + m_sellable = rhs.m_sellable; + m_type = rhs.m_type; + m_price = rhs.m_price; + m_description = rhs.m_description; + m_effects.clear(); + foreach (ItemEffect* effect, rhs.m_effects) + m_effects.append(new ItemEffect(pokemod(), *effect, effect->id())); return *this; } diff --git a/pokemod/Item.h b/pokemod/Item.h index d5d4e087..5e2995a9 100644 --- a/pokemod/Item.h +++ b/pokemod/Item.h @@ -1,84 +1,84 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Item.h -// Purpose: Define an item -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:16:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class ItemEffect; class Pokemod; class Item : public Object { public: - Item(const Pokemod* par, const int _id); - Item(const Pokemod* par, const Item& i, const int _id); - Item(const Pokemod* par, const QString& fname, const int _id = -1); + Item(const Pokemod* pokemod, const int id); + Item(const Pokemod* pokemod, const Item& item, const int id); + Item(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~Item(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setSellable(const bool s); - void setType(const int t) throw(BoundsException); - void setPrice(const int p) throw(BoundsException); - void setDescription(const QString& d); + void setName(const QString& name); + void setSellable(const bool sellable); + void setType(const int type) throw(BoundsException); + void setPrice(const int price) throw(BoundsException); + void setDescription(const QString& description); - QString getName() const; - bool getSellable() const; - int getType() const; - int getPrice() const; - QString getDescription() const; + QString name() const; + bool sellable() const; + int type() const; + int price() const; + QString description() const; - const ItemEffect* getEffect(const int i) const throw(IndexException); - ItemEffect* getEffect(const int i) throw(IndexException); - const ItemEffect* getEffectByID(const int i) const throw(IndexException); - ItemEffect* getEffectByID(const int i) throw(IndexException); - int getEffectIndex(const int _id) const; - int getEffectCount() const; + const ItemEffect* effect(const int index) const throw(IndexException); + ItemEffect* effect(const int index) throw(IndexException); + const ItemEffect* effectById(const int id) const throw(IndexException); + ItemEffect* effectById(const int id) throw(IndexException); + int effectIndex(const int id) const; + int effectCount() const; ItemEffect* newEffect(); - ItemEffect* newEffect(const QString& fname); - ItemEffect* newEffect(const ItemEffect& e); - void deleteEffect(const int i) throw(IndexException); + ItemEffect* newEffect(const QString& fileName); + ItemEffect* newEffect(const ItemEffect& effect); + void deleteEffect(const int index) throw(IndexException); + void deleteEffectById(const int index) throw(IndexException); Item& operator=(const Item& rhs); private: bool validate() const; - int getNewId() const; + int effectId() const; - QString name; - bool sellable; - int type; - int price; - QString description; + QString m_name; + bool m_sellable; + int m_type; + int m_price; + QString m_description; - QList<ItemEffect*> effects; + QList<ItemEffect*> m_effects; }; #endif diff --git a/pokemod/ItemEffect.cpp b/pokemod/ItemEffect.cpp index d2e5b2d2..5d663cf3 100644 --- a/pokemod/ItemEffect.cpp +++ b/pokemod/ItemEffect.cpp @@ -1,27 +1,26 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/ItemEffect.cpp -// Purpose: Define an effect of an item -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:25:26 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ + +// Pokemod includes #include "Pokemod.h" #include "MapWildList.h" + +// Header include #include "ItemEffect.h" const QStringList ItemEffect::EffectStr = QStringList() << "HP Cure" << "Revive" << "Cure Status" << "Level Boost" << "Stat Boost" << "Flinch" << "Go First" << "Keep Alive" << "Modify Stat (Battle Only)" << "Shield (Battle Only)" << "Run (Battle Only)" << "PP Boost" << "Type Boost" << "PP Restore" << "Experience Share" << "Fishing Rod" << "Repel" << "Escape" << "TM" << "HM" << "Map" << "Ball" << "Itemfinder" << "Bike" << "Scope" << "Coin" << "Coin Case" << "Berry" << "Acorn"; @@ -33,36 +32,36 @@ const QStringList ItemEffect::SpecialPhysicalStr = QStringList() << "Special" << const QStringList ItemEffect::BallTypeStr = QStringList() << "Regular" << "Master" << "Level" << "Love" << "Area" << "Time" << "Battle" << "Friend" << "Stat" << "Type" << "Weight"; const QStringList ItemEffect::BerryTypeStr = QStringList() << "HP Cure" << "Status Cure"; -ItemEffect::ItemEffect(const Pokemod* par, const int _id) : - Object("ItemEffect", par, _id), - overworld(false), - battle(false), - held(false), - effect(-1), - val1(-1), - val2(-1), - val3(-1), - val4(1, 1) +ItemEffect::ItemEffect(const Pokemod* pokemod, const int id) : + Object("ItemEffect", pokemod, id), + m_overworld(false), + m_battle(false), + m_held(false), + m_effect(INT_MAX), + m_value1(INT_MAX), + m_value2(INT_MAX), + m_value3(INT_MAX), + m_value4(1, 1) { } -ItemEffect::ItemEffect(const Pokemod* par, const ItemEffect& e, const int _id) : - Object("ItemEffect", par, _id) +ItemEffect::ItemEffect(const Pokemod* pokemod, const ItemEffect& effect, const int id) : + Object("ItemEffect", pokemod, id) { - *this = e; + *this = effect; } -ItemEffect::ItemEffect(const Pokemod* par, const QString& fname, const int _id) : - Object("ItemEffect", par, _id) +ItemEffect::ItemEffect(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("ItemEffect", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool ItemEffect::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Effect with id %1---").arg(id), Pokemod::V_Msg); - switch (effect) + pokemod()->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); + switch (m_effect) { case E_Revive: case E_LevelBoost: @@ -81,9 +80,9 @@ bool ItemEffect::validate() const case E_CoinCase: case E_Acorn: case E_Evolution: - if (!overworld) + if (!m_overworld) { - pokemod->validationMsg("Effect only works in the overworld"); + pokemod()->validationMsg("Effect only works in the overworld"); valid = false; } break; @@ -97,48 +96,48 @@ bool ItemEffect::validate() const case E_ExpShare: case E_Ball: case E_Berry: - if (overworld) + if (m_overworld) { valid = false; - pokemod->validationMsg("Effect cannot work in the overworld"); + pokemod()->validationMsg("Effect cannot work in the overworld"); } break; } - if (effect < E_End) + if (m_effect < E_End) { bool ok = true; - switch (effect) + switch (m_effect) { case E_HPCure: case E_Revive: - if ((val4 != R_Absolute) || !val1) + if ((m_value4 != R_Absolute) || !m_value1) ok = false; break; case E_LevelBoost: case E_ShieldBattle: case E_PPBoost: case E_Repel: - if (!val1) + if (!m_value1) ok = false; break; case E_StatBoost: case E_Acorn: - if ((val1 < 0) || (65536 <= val1)) + if ((m_value1 < 0) || (65536 <= m_value1)) ok = false; break; case E_ModifyStatBattle: - if ((val1 < -12) || (12 < val1)) + if ((m_value1 < -12) || (12 < m_value1)) ok = false; break; case E_Ball: - switch (val2) + switch (m_value2) { case B_Regular: - if (256 <= val1) + if (256 <= m_value1) ok = false; break; case B_Level: - if (pokemod->getRules()->getMaxLevel() < val1) + if (pokemod()->rules()->maxLevel() < m_value1) ok = false; break; case B_Master: @@ -159,86 +158,86 @@ bool ItemEffect::validate() const } if (!ok) { - pokemod->validationMsg("Invalid val1"); + pokemod()->validationMsg("Invalid value 1"); valid = false; ok = true; } - switch (effect) + switch (m_effect) { case E_HPCure: case E_Revive: - if (R_End <= val2) + if (R_End <= m_value2) ok = false; break; case E_CureStatus: - if (Pokemod::STS_End <= val2) + if (Pokemod::STS_End <= m_value2) ok = false; break; case E_StatBoost: - if ((val2 <= 0) || (65536 <= val2)) + if ((m_value2 <= 0) || (65536 <= m_value2)) ok = false; break; case E_ModifyStatBattle: - if (Pokemod::ST_End_Battle <= val2) + if (Pokemod::ST_End_Battle <= m_value2) ok = false; break; case E_ShieldBattle: - if (SP_End <= val2) + if (SP_End <= m_value2) ok = false; break; case E_TypeBoost: - if (pokemod->getTypeIndex(val2) == -1) + if (pokemod()->typeIndex(m_value2) == INT_MAX) ok = false; break; case E_PPRestore: - if (A_End <= val2) + if (A_End <= m_value2) ok = false; break; case E_Repel: - if (RP_End <= val2) + if (RP_End <= m_value2) ok = false; break; case E_Escape: - if (ES_End <= val2) + if (ES_End <= m_value2) ok = false; break; case E_TM: case E_HM: - if (pokemod->getMoveIndex(val2) == -1) + if (pokemod()->moveIndex(m_value2) == INT_MAX) ok = false; break; case E_Ball: - if (B_End <= val2) + if (B_End <= m_value2) ok = false; break; case E_Berry: - if (B2_End <= val2) + if (B2_End <= m_value2) ok = false; break; case E_Coin: case E_CoinCase: - if (val2 <= 0) + if (m_value2 <= 0) ok = false; break; case E_Acorn: - if (pokemod->getItemIndex(val2) == -1) + if (pokemod()->itemIndex(m_value2) == INT_MAX) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid val2"); + pokemod()->validationMsg("Invalid value 2"); valid = false; ok = true; } - switch (effect) + switch (m_effect) { case E_StatBoost: - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= val3) + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value3) ok = false; break; case E_Ball: - switch (val2) + switch (m_value2) { case B_Regular: case B_Master: @@ -249,32 +248,32 @@ bool ItemEffect::validate() const case B_Weight: break; case B_Area: - if (MapWildList::End <= val3) + if (MapWildList::End <= m_value3) ok = false; break; case B_Time: - if (pokemod->getTimeIndex(val3) == -1) + if (pokemod()->timeIndex(m_value3) == INT_MAX) ok = false; break; case B_Stat: - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= val3) + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value3) ok = false; break; case B_Type: - if (pokemod->getTypeIndex(val3) == -1) + if (pokemod()->typeIndex(m_value3) == INT_MAX) ok = false; break; } break; case E_Berry: - switch (val2) + switch (m_value2) { case B2_HPCure: - if (Pokemod::REL_End <= val3) + if (Pokemod::REL_End <= m_value3) ok = false; break; case B2_StatusCure: - if (Pokemod::STS_End <= val3) + if (Pokemod::STS_End <= m_value3) ok = false; break; default: @@ -285,58 +284,57 @@ bool ItemEffect::validate() const } if (!ok) { - pokemod->validationMsg("Invalid val3"); + pokemod()->validationMsg("Invalid value 3"); valid = false; } } else { - pokemod->validationMsg("Invalid effect"); + pokemod()->validationMsg("Invalid effect"); valid = false; } return valid; } -void ItemEffect::load(const QString& fname, const int _id) throw(Exception) +void ItemEffect::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("overworld", overworld, false); - ini.getValue("battle", battle, false); - ini.getValue("held", held, false); - ini.getValue("effect", effect); - ini.getValue("val1", val1); - ini.getValue("val2", val2); - ini.getValue("val3", val3); - ini.getValue("val4-n", i, 1); - ini.getValue("val4-n", j, 1); - val4.set(i, j); + ini.getValue("overworld", m_overworld, false); + ini.getValue("battle", m_battle, false); + ini.getValue("held", m_held, false); + ini.getValue("effect", m_effect); + ini.getValue("value1", m_value1); + ini.getValue("value2", m_value2); + ini.getValue("value3", m_value3); + ini.getValue("value4-n", i, 1); + ini.getValue("value4-n", j, 1); + m_value4.set(i, j); } void ItemEffect::save(const QString& item) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("overworld", overworld); - ini.addField("battle", battle); - ini.addField("held", held); - ini.addField("effect", effect); - ini.addField("val1", val1); - ini.addField("val2", val2); - ini.addField("val3", val3); - ini.addField("val4-n", val4.getNum()); - ini.addField("val4-d", val4.getDenom()); - ini.save(QString("%1/item/%2/effect/%3.pini").arg(pokemod->getPath()).arg(item).arg(id)); + ini.addField("id", id()); + ini.addField("overworld", m_overworld); + ini.addField("battle", m_battle); + ini.addField("held", m_held); + ini.addField("effect", m_effect); + ini.addField("value1", m_value1); + ini.addField("value2", m_value2); + ini.addField("value3", m_value3); + ini.addField("value4-n", m_value4.numerator()); + ini.addField("value4-d", m_value4.denominator()); + ini.save(QString("%1/item/%2/effect/%3.pini").arg(pokemod()->path()).arg(item).arg(id())); } -void ItemEffect::setOverworld(const bool o) throw(Exception) +void ItemEffect::setOverworld(const bool overworld) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Revive: case E_LevelBoost: @@ -355,8 +353,8 @@ void ItemEffect::setOverworld(const bool o) throw(Exception) case E_CoinCase: case E_Acorn: case E_Evolution: - if (!o) - throw(Exception(className, "overworld mismatch")); + if (!overworld) + throw(Exception(className(), "overworld mismatch")); break; case E_Flinch: case E_First: @@ -368,28 +366,28 @@ void ItemEffect::setOverworld(const bool o) throw(Exception) case E_ExpShare: case E_Ball: case E_Berry: - if (o) - throw(Exception(className, "overworld mismatch")); + if (overworld) + throw(Exception(className(), "overworld mismatch")); break; } - overworld = o; + m_overworld = overworld; } -void ItemEffect::setBattle(const bool b) +void ItemEffect::setBattle(const bool battle) { - battle = b; + m_battle = battle; } -void ItemEffect::setHeld(const bool h) +void ItemEffect::setHeld(const bool held) { - held = h; + m_held = held; } -void ItemEffect::setEffect(const int e) throw(Exception) +void ItemEffect::setEffect(const int effect) throw(Exception) { - if (E_End <= e) - throw(BoundsException(className, "effect out-of-bounds")); - switch (e) + if (E_End <= effect) + throw(BoundsException(className(), "effect out-of-bounds")); + switch (effect) { case E_Revive: case E_LevelBoost: @@ -408,8 +406,7 @@ void ItemEffect::setEffect(const int e) throw(Exception) case E_CoinCase: case E_Acorn: case E_Evolution: - if (!overworld) - throw(Exception(className, "overworld mismatch")); + m_overworld = true; break; case E_Flinch: case E_First: @@ -421,56 +418,55 @@ void ItemEffect::setEffect(const int e) throw(Exception) case E_ExpShare: case E_Ball: case E_Berry: - if (overworld) - throw(Exception(className, "overworld mismatch")); + m_overworld = false; break; } - effect = e; - val1 = 0; - val2 = -1; - val3 = -1; - val4.set(1, 1, ((e == E_TypeBoost) || (e == E_PPBoost)) ? Frac::Over1 : Frac::Proper); + m_effect = effect; + m_value1 = 0; + m_value2 = INT_MAX; + m_value3 = INT_MAX; + m_value4.set(1, 1, ((E_TypeBoost == effect) || (E_PPBoost == effect)) ? Frac::Over1 : Frac::Proper); } -void ItemEffect::setVal1(const int v1) throw(Exception) +void ItemEffect::setValue1(const int value1) throw(Exception) { - switch (effect) + switch (m_effect) { case E_HPCure: case E_Revive: - if ((val4 != R_Absolute) || !val1) - throw(BoundsException(className, "val1")); + if ((m_value4 != R_Absolute) || !value1) + throw(BoundsException(className(), "value1")); break; case E_LevelBoost: case E_ShieldBattle: case E_PPBoost: case E_Repel: - if (!val1) - throw(BoundsException(className, "val1")); + if (!value1) + throw(BoundsException(className(), "value1")); break; case E_StatBoost: case E_Acorn: - if ((val1 < 0) || (65536 <= val1)) - throw(BoundsException(className, "val1")); + if ((value1 < 0) || (65536 <= value1)) + throw(BoundsException(className(), "value1")); break; case E_ModifyStatBattle: - if ((val1 < -12) || (12 < val1)) - throw(BoundsException(className, "val1")); + if ((value1 < -12) || (12 < value1)) + throw(BoundsException(className(), "value1")); break; case E_Fish: case E_Coin: case E_CoinCase: break; case E_Ball: - switch (val2) + switch (m_value2) { case B_Regular: - if (256 <= val1) - throw(BoundsException(className, "val1")); + if (256 <= value1) + throw(BoundsException(className(), "value1")); break; case B_Level: - if (pokemod->getRules()->getMaxLevel() < val1) - throw(BoundsException(className, "val1")); + if (pokemod()->rules()->maxLevel() < value1) + throw(BoundsException(className(), "value1")); break; case B_Master: case B_Love: @@ -483,219 +479,153 @@ void ItemEffect::setVal1(const int v1) throw(Exception) case B_Weight: break; default: - throw(BoundsException(className, "val1")); + throw(BoundsException(className(), "value1")); } break; default: - throw(UnusedException(className, "val1")); + throw(UnusedException(className(), "value1")); break; } - val1 = v1; + m_value1 = value1; } -void ItemEffect::setVal2(const int v2) throw(Exception) +void ItemEffect::setValue2(const int value2) throw(Exception) { - switch (effect) + switch (m_effect) { case E_HPCure: case E_Revive: - if (R_End <= val2) - throw(BoundsException(className, "val2")); + if (R_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_CureStatus: - if (Pokemod::STS_End <= val2) - throw(BoundsException(className, "val2")); + if (Pokemod::STS_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_StatBoost: - if ((val2 <= 0) || (65536 <= val2)) - throw(BoundsException(className, "val2")); + if ((value2 <= 0) || (65536 <= value2)) + throw(BoundsException(className(), "value2")); break; case E_ModifyStatBattle: - if (Pokemod::ST_End_Battle <= val2) - throw(BoundsException(className, "val2")); + if (Pokemod::ST_End_Battle <= value2) + throw(BoundsException(className(), "value2")); break; case E_ShieldBattle: - if (SP_End <= val2) - throw(BoundsException(className, "val2")); + if (SP_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_TypeBoost: - if (pokemod->getTypeIndex(val2) == -1) - throw(BoundsException(className, "val2")); + if (pokemod()->typeIndex(value2) == INT_MAX) + throw(BoundsException(className(), "value2")); break; case E_PPRestore: - if (A_End <= val2) - throw(BoundsException(className, "val2")); + if (A_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Repel: - if (RP_End <= val2) - throw(BoundsException(className, "val2")); + if (RP_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Escape: - if (ES_End <= val2) - throw(BoundsException(className, "val2")); + if (ES_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_TM: case E_HM: - if (pokemod->getMoveIndex(val2) == -1) - throw(BoundsException(className, "val2")); + if (pokemod()->moveIndex(value2) == INT_MAX) + throw(BoundsException(className(), "value2")); break; case E_Ball: - if (B_End <= val2) - throw(BoundsException(className, "val2")); + if (B_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Scope: break; case E_Berry: - if (B2_End <= val2) - throw(BoundsException(className, "val2")); + if (B2_End <= value2) + throw(BoundsException(className(), "value2")); break; case E_Coin: case E_CoinCase: - if (val2 <= 0) - throw(BoundsException(className, "val2")); + if (value2 <= 0) + throw(BoundsException(className(), "value2")); break; case E_Acorn: - if (pokemod->getItemIndex(val2) == -1) - throw(BoundsException(className, "val2")); + if (pokemod()->itemIndex(value2) == INT_MAX) + throw(BoundsException(className(), "value2")); break; default: - throw(UnusedException(className, "val2")); + throw(UnusedException(className(), "value2")); break; } - val2 = v2; + m_value2 = value2; } -void ItemEffect::setVal3(const int v3) throw(Exception) +void ItemEffect::setValue3(const int value3) throw(Exception) { - switch (effect) + switch (m_effect) { case E_StatBoost: - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= val3) - throw(BoundsException(className, "val3")); + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) + throw(BoundsException(className(), "value3")); break; case E_Ball: - switch (val2) + switch (m_value2) { case B_Level: case B_Friend: case B_Weight: break; case B_Area: - if (MapWildList::End <= val3) - throw(BoundsException(className, "val3")); + if (MapWildList::End <= value3) + throw(BoundsException(className(), "value3")); break; case B_Time: - if (pokemod->getTimeIndex(val3) == -1) - throw(BoundsException(className, "val3")); + if (pokemod()->timeIndex(value3) == INT_MAX) + throw(BoundsException(className(), "value3")); break; case B_Stat: - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= val3) - throw(BoundsException(className, "val3")); + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value3) + throw(BoundsException(className(), "value3")); break; case B_Type: - if (pokemod->getTypeIndex(val3) == -1) - throw(BoundsException(className, "val3")); + if (pokemod()->typeIndex(value3) == INT_MAX) + throw(BoundsException(className(), "value3")); break; case B_Regular: case B_Master: case B_Love: case B_Battle: - throw(UnusedException(className, "val3")); + throw(UnusedException(className(), "value3")); break; } break; case E_Berry: - switch (val2) + switch (m_value2) { case B2_HPCure: - if (Pokemod::REL_End <= val3) - throw(BoundsException(className, "val3")); + if (Pokemod::REL_End <= value3) + throw(BoundsException(className(), "value3")); break; case B2_StatusCure: - if (Pokemod::STS_End <= val3) - throw(BoundsException(className, "val3")); + if (Pokemod::STS_End <= value3) + throw(BoundsException(className(), "value3")); break; default: - throw(UnusedException(className, "val3")); + throw(UnusedException(className(), "value3")); break; } break; default: - throw(UnusedException(className, "val3")); - break; - } - val3 = v3; -} - -void ItemEffect::setVal4(const int n, const int d) throw(Exception) -{ - switch (effect) - { - case E_CureStatus: - case E_LevelBoost: - case E_StatBoost: - case E_ModifyStatBattle: - case E_Fish: - case E_Escape: - case E_TM: - case E_HM: - case E_Map: - case E_Itemfinder: - case E_Bike: - case E_Scope: - case E_Coin: - case E_CoinCase: - case E_Acorn: - case E_Evolution: - throw(UnusedException(className, "val4")); - case E_Ball: - if (val2 == B_Master) - throw(UnusedException(className, "val4")); - break; - case E_Berry: - if (val2 != B2_HPCure) - throw(UnusedException(className, "val4")); - break; - } - val4.set(n, d); -} - -void ItemEffect::setVal4Num(const int n) throw(Exception) -{ - switch (effect) - { - case E_CureStatus: - case E_LevelBoost: - case E_StatBoost: - case E_ModifyStatBattle: - case E_Fish: - case E_Escape: - case E_TM: - case E_HM: - case E_Map: - case E_Itemfinder: - case E_Bike: - case E_Scope: - case E_Coin: - case E_CoinCase: - case E_Acorn: - case E_Evolution: - throw(UnusedException(className, "val4")); - case E_Ball: - if (val2 == B_Master) - throw(UnusedException(className, "val4")); - break; - case E_Berry: - if (val2 != B2_HPCure) - throw(UnusedException(className, "val4")); + throw(UnusedException(className(), "value3")); break; } - val4.setNum(n); + m_value3 = value3; } -void ItemEffect::setVal4Denom(const int d) throw(Exception) +void ItemEffect::setValue4(const int numerator, const int denominator) throw(Exception) { - switch (effect) + switch (m_effect) { case E_CureStatus: case E_LevelBoost: @@ -713,70 +643,70 @@ void ItemEffect::setVal4Denom(const int d) throw(Exception) case E_CoinCase: case E_Acorn: case E_Evolution: - throw(UnusedException(className, "val4")); + throw(UnusedException(className(), "value4")); case E_Ball: - if (val2 == B_Master) - throw(UnusedException(className, "val4")); + if (m_value2 == B_Master) + throw(UnusedException(className(), "value4")); break; case E_Berry: - if (val2 != B2_HPCure) - throw(UnusedException(className, "val4")); + if (m_value2 != B2_HPCure) + throw(UnusedException(className(), "value4")); break; } - val4.setDenom(d); + m_value4.set(numerator, denominator); } -bool ItemEffect::getOverworld() const +bool ItemEffect::overworld() const { - return overworld; + return m_overworld; } -bool ItemEffect::getBattle() const +bool ItemEffect::battle() const { - return battle; + return m_battle; } -bool ItemEffect::getHeld() const +bool ItemEffect::held() const { - return held; + return m_held; } -int ItemEffect::getEffect() const +int ItemEffect::effect() const { - return effect; + return m_effect; } -int ItemEffect::getVal1() const +int ItemEffect::value1() const { - return val1; + return m_value1; } -int ItemEffect::getVal2() const +int ItemEffect::value2() const { - return val2; + return m_value2; } -int ItemEffect::getVal3() const +int ItemEffect::value3() const { - return val3; + return m_value3; } -Frac ItemEffect::getVal4() const +Frac ItemEffect::value4() const { - return val4; + return m_value4; } ItemEffect& ItemEffect::operator=(const ItemEffect& rhs) { if (this == &rhs) return *this; - overworld = rhs.overworld; - battle = rhs.battle; - held = rhs.battle; - effect = rhs.effect; - val1 = rhs.val1; - val2 = rhs.val2; - val3 = rhs.val3; - val4 = rhs.val4; + m_overworld = rhs.m_overworld; + m_battle = rhs.m_battle; + m_held = rhs.m_held; + m_effect = rhs.m_effect; + m_value1 = rhs.m_value1; + m_value2 = rhs.m_value2; + m_value3 = rhs.m_value3; + m_value4 = rhs.m_value4; return *this; } diff --git a/pokemod/ItemEffect.h b/pokemod/ItemEffect.h index b3dfdd7b..9f344b64 100644 --- a/pokemod/ItemEffect.h +++ b/pokemod/ItemEffect.h @@ -1,36 +1,35 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/ItemEffect.h -// Purpose: Define an effect of an item -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:25:26 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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_ITEMEFFECT__ #define __POKEMOD_ITEMEFFECT__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod include #include "Object.h" +// Forward declarations class Pokemod; class ItemEffect : public Object @@ -138,47 +137,43 @@ class ItemEffect : public Object }; static const QStringList BerryTypeStr; - ItemEffect(const Pokemod* par, const int _id); - ItemEffect(const Pokemod* par, const ItemEffect& e, const int _id); - ItemEffect(const Pokemod* par, const QString& fname, const int _id = -1); + ItemEffect(const Pokemod* pokemod, const int id); + ItemEffect(const Pokemod* pokemod, const ItemEffect& effect, const int id); + ItemEffect(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& item) const throw(Exception); - void setOverworld(const bool o) throw(Exception); - void setBattle(const bool b); - void setHeld(const bool h); - void setEffect(const int e) throw(Exception); - void setVal1(const int v1) throw(Exception); - void setVal2(const int v2) throw(Exception); - void setVal3(const int v3) throw(Exception); - void setVal4(const int n, const int d) throw(Exception); - void setVal4Num(const int n) throw(Exception); - void setVal4Denom(const int d) throw(Exception); + void setOverworld(const bool overworld) throw(Exception); + void setBattle(const bool battle); + void setHeld(const bool held); + void setEffect(const int effect) throw(Exception); + void setValue1(const int value1) throw(Exception); + void setValue2(const int value2) throw(Exception); + void setValue3(const int value3) throw(Exception); + void setValue4(const int numerator, const int demoninator) throw(Exception); - bool getOverworld() const; - bool getBattle() const; - bool getHeld() const; - int getEffect() const; - int getVal1() const; - int getVal2() const; - int getVal3() const; - Frac getVal4() const; - int getVal4Num() const; - int getVal4Denom() const; + bool overworld() const; + bool battle() const; + bool held() const; + int effect() const; + int value1() const; + int value2() const; + int value3() const; + Frac value4() const; ItemEffect& operator=(const ItemEffect& rhs); private: bool validate() const; - bool overworld; - bool battle; - bool held; - int effect; - int val1; - int val2; - int val3; - Frac val4; + bool m_overworld; + bool m_battle; + bool m_held; + int m_effect; + int m_value1; + int m_value2; + int m_value3; + Frac m_value4; }; #endif diff --git a/pokemod/ItemType.cpp b/pokemod/ItemType.cpp index 80948fab..cd27a558 100644 --- a/pokemod/ItemType.cpp +++ b/pokemod/ItemType.cpp @@ -1,150 +1,148 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/ItemType.cpp -// Purpose: Define a type of item and how much can be stored -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:06:40 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QFile> +// Pokemod includes #include "Pokemod.h" + +// Header include #include "ItemType.h" QStringList ItemType::CountStr = QStringList() << "Distinct" << "Total"; -ItemType::ItemType(const Pokemod* par, const int _id) : - Object("ItemType", par, _id), - name(""), - computer(0), - player(1), - count(0) +ItemType::ItemType(const Pokemod* pokemod, const int id) : + Object("ItemType", pokemod, id), + m_name(""), + m_computer(0), + m_player(1), + m_count(0) { } -ItemType::ItemType(const Pokemod* par, const ItemType& i, const int _id) : - Object("ItemType", par, _id) +ItemType::ItemType(const Pokemod* pokemod, const ItemType& itemType, const int id) : + Object("ItemType", pokemod, id) { - *this = i; + *this = itemType; } -ItemType::ItemType(const Pokemod* par, const QString& fname, const int _id) : - Object("ItemType", par, _id) +ItemType::ItemType(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("ItemType", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool ItemType::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Item Type \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Item Type \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (!player) + if (!m_player) { - pokemod->validationMsg("Invalid storage with the player"); + pokemod()->validationMsg("Invalid storage with the player"); valid = false; } - if (End <= count) + if (End <= m_count) { - pokemod->validationMsg("Invalid count"); + pokemod()->validationMsg("Invalid count"); valid = false; } return valid; } -void ItemType::load(const QString& fname, const int _id) throw(Exception) +void ItemType::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - ini.getValue("computer", computer, 0); - ini.getValue("player", player, 1); - ini.getValue("count", count); + setId(id); + ini.getValue("name", m_name); + ini.getValue("computer", m_computer, 0); + ini.getValue("player", m_player, 1); + ini.getValue("count", m_count); } void ItemType::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("computer", computer); - ini.addField("player", player); - ini.addField("count", count); - ini.save(QString("%1/itemtype/%2.pini").arg(pokemod->getPath()).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("computer", m_computer); + ini.addField("player", m_player); + ini.addField("count", m_count); + ini.save(QString("%1/itemtype/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void ItemType::setName(const QString& n) +void ItemType::setName(const QString& name) { - name = n; + m_name = name; } -void ItemType::setComputer(const int c) +void ItemType::setComputer(const int computer) { - computer = c; + m_computer = computer; } -void ItemType::setPlayer(const int p) throw(BoundsException) +void ItemType::setPlayer(const int player) throw(BoundsException) { - if (!p) - throw(BoundsException(className, "player")); - player = p; + if (!player) + throw(BoundsException(className(), "player")); + m_player = player; } -void ItemType::setCount(const int c) throw(BoundsException) +void ItemType::setCount(const int count) throw(BoundsException) { - if (End <= c) - throw(BoundsException(className, "count")); - count = c; + if (End <= count) + throw(BoundsException(className(), "count")); + m_count = count; } -QString ItemType::getName() const +QString ItemType::name() const { - return name; + return m_name; } -int ItemType::getComputer() const +int ItemType::computer() const { - return computer; + return m_computer; } -int ItemType::getPlayer() const +int ItemType::player() const { - return player; + return m_player; } -int ItemType::getCount() const +int ItemType::count() const { - return count; + return m_count; } ItemType& ItemType::operator=(const ItemType& rhs) { if (this == &rhs) return *this; - name = rhs.name; - computer = rhs.computer; - player = rhs.player; - count = rhs.count; + m_name = rhs.m_name; + m_computer = rhs.m_computer; + m_player = rhs.m_player; + m_count = rhs.m_count; return *this; } diff --git a/pokemod/ItemType.h b/pokemod/ItemType.h index 12cbb7f4..49a1fb11 100644 --- a/pokemod/ItemType.h +++ b/pokemod/ItemType.h @@ -1,35 +1,34 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/ItemType.h -// Purpose: Define a type of item and how much can be stored -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:06:40 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class ItemType : public Object @@ -43,31 +42,31 @@ class ItemType : public Object }; static QStringList CountStr; - ItemType(const Pokemod* par, const int _id); - ItemType(const Pokemod* par, const ItemType& i, const int _id); - ItemType(const Pokemod* par, const QString& fname, const int _id = -1); + ItemType(const Pokemod* pokemod, const int id); + ItemType(const Pokemod* pokemod, const ItemType& itemType, const int id); + ItemType(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setComputer(const int c); - void setPlayer(const int p) throw(BoundsException); - void setCount(const int c) throw(BoundsException); + void setName(const QString& name); + void setComputer(const int computer); + void setPlayer(const int player) throw(BoundsException); + void setCount(const int count) throw(BoundsException); - QString getName() const; - int getComputer() const; - int getPlayer() const; - int getCount() const; + QString name() const; + int computer() const; + int player() const; + int count() const; ItemType& operator=(const ItemType& rhs); private: bool validate() const; - QString name; - int computer; - int player; - int count; + QString m_name; + int m_computer; + int m_player; + int m_count; }; #endif diff --git a/pokemod/Map.cpp b/pokemod/Map.cpp index e3adeff5..27f6f695 100644 --- a/pokemod/Map.cpp +++ b/pokemod/Map.cpp @@ -1,242 +1,183 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Map.cpp -// Purpose: Define a map for the game -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Mon May 28 21:45:48 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QDir> #include <QMap> -#include <QMapIterator> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "MapEffect.h" #include "MapTrainer.h" #include "MapWarp.h" #include "MapWildList.h" + +// Header include #include "Map.h" const QStringList Map::TypeStr = QStringList() << "Outdoor" << "Dungeon" << "Building"; -Map::Map(const Pokemod* par, const int _id) : - Object("Map", par, _id), - name(""), - flyWarp(-1), - type(-1) +Map::Map(const Pokemod* pokemod, const int id) : + Object("Map", pokemod, id), + m_name(""), + m_flyWarp(INT_MAX), + m_type(INT_MAX) { } -Map::Map(const Pokemod* par, const Map& m, const int _id) : - Object("Map", par, _id) +Map::Map(const Pokemod* pokemod, const Map& map, const int id) : + Object("Map", pokemod, id) { - *this = m; + *this = map; } -Map::Map(const Pokemod* par, const QString& fname, const int _id) : - Object("Map", par, _id) +Map::Map(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Map", pokemod, id) { - load(fname, _id); + load(fileName, id); } Map::~Map() { - for (QListIterator<MapEffect*> i(effects); i.hasNext(); ) - delete i.next(); - for (QListIterator<MapTrainer*> i(trainers); i.hasNext(); ) - delete i.next(); - for (QListIterator<MapWarp*> i(warps); i.hasNext(); ) - delete i.next(); - for (QListIterator<MapWildList*> i(wildLists); i.hasNext(); ) - delete i.next(); + foreach (MapEffect* effect, m_effects) + delete effect; + foreach (MapTrainer* trainer, m_trainers) + delete trainer; + foreach (MapWarp* warp, m_warps) + delete warp; + foreach (MapWildList* wildList, m_wildLists) + delete wildList; } bool Map::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Map \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Map \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("name is not defined"); + pokemod()->validationMsg("name is not defined"); valid = false; } - if ((flyWarp != -1) && (getWarpIndex(flyWarp) == -1)) + if ((m_flyWarp != INT_MAX) && (warpIndex(m_flyWarp) == INT_MAX)) { - pokemod->validationMsg("Invalid fly destination warp"); + pokemod()->validationMsg("Invalid fly destination warp"); valid = false; } - if (type < End) + if (m_type < End) { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Invalid type"); valid = false; } - QMap<int, int> idChecker; - QMap<QString, int> nameChecker; - if (getEffectCount()) + QMap<int, bool> idChecker; + if (effectCount()) { - for (QListIterator<MapEffect*> i(effects); i.hasNext(); i.next()) + foreach (MapEffect* effect, m_effects) { - if (!i.peekNext()->isValid()) - valid = false; - if (getWidth() <= i.peekNext()->getCoordinate().getX()) - { - pokemod->validationMsg("Invalid x coordinate"); - valid = false; - } - if (getHeight() <= i.peekNext()->getCoordinate().getY()) - { - pokemod->validationMsg("Invalid y coordinate"); + if (!effect->isValid()) valid = false; - } - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + if (idChecker[effect->id()]) + pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); + idChecker[effect->id()] = true; + if (width() <= effect->coordinate().x()) { - pokemod->validationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid x coordinate"); valid = false; } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + if (height() <= effect->coordinate().y()) { - pokemod->validationMsg(QString("There are %1 effects with the name \"%2\"").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid y coordinate"); valid = false; } } idChecker.clear(); - nameChecker.clear(); } else - pokemod->validationMsg("There are no effects", Pokemod::V_Warn); - if (getTrainerCount()) + pokemod()->validationMsg("There are no effects", Pokemod::V_Warn); + if (trainerCount()) { - for (QListIterator<MapTrainer*> i(trainers); i.hasNext(); i.next()) + foreach (MapTrainer* trainer, m_trainers) { - if (!i.peekNext()->isValid()) + if (!trainer->isValid()) valid = false; - if (getWidth() <= i.peekNext()->getCoordinate().getX()) + if (idChecker[trainer->id()]) + pokemod()->validationMsg(QString("Duplicate trainer with id %1").arg(trainer->id())); + idChecker[trainer->id()] = true; + if (width() <= trainer->coordinate().x()) { - pokemod->validationMsg("Invalid x coordinate"); + pokemod()->validationMsg("Invalid x coordinate"); valid = false; } - if (getHeight() <= i.peekNext()->getCoordinate().getY()) + if (height() <= trainer->coordinate().y()) { - pokemod->validationMsg("Invalid y coordinate"); - valid = false; - } - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 trainers with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 trainers with the name \"%2\"").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid y coordinate"); valid = false; } } idChecker.clear(); - nameChecker.clear(); } else - pokemod->validationMsg("There are no trainers", Pokemod::V_Warn); - if (getWarpCount()) + pokemod()->validationMsg("There are no trainers", Pokemod::V_Warn); + if (warpCount()) { - for (QListIterator<MapWarp*> i(warps); i.hasNext(); i.next()) + foreach (MapWarp* warp, m_warps) { - if (!i.peekNext()->isValid()) - valid = false; - if (getWidth() <= i.peekNext()->getCoordinate().getX()) - { - pokemod->validationMsg("Invalid x coordinate"); - valid = false; - } - if (getHeight() <= i.peekNext()->getCoordinate().getY()) - { - pokemod->validationMsg("Invalid y coordinate"); + if (!warp->isValid()) valid = false; - } - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + if (idChecker[warp->id()]) + pokemod()->validationMsg(QString("Duplicate warp with id %1").arg(warp->id())); + idChecker[warp->id()] = true; + if (width() <= warp->coordinate().x()) { - pokemod->validationMsg(QString("There are %1 warps with id %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid x coordinate"); valid = false; } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + if (height() <= warp->coordinate().y()) { - pokemod->validationMsg(QString("There are %1 warps with the name \"%2\"").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid y coordinate"); valid = false; } } idChecker.clear(); - nameChecker.clear(); } else { - pokemod->validationMsg("There are no warps"); + pokemod()->validationMsg("There are no warps"); valid = false; } - if (getWildListCount()) + if (wildListCount()) { - for (QListIterator<MapWildList*> i(wildLists); i.hasNext(); i.next()) + foreach (MapWildList* wildList, m_wildLists) { - if (!i.peekNext()->isValid()) + if (!wildList->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; + if (idChecker[wildList->id()]) + pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(wildList->id())); + idChecker[wildList->id()] = true; } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 wild lists with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - idChecker.clear(); } else - pokemod->validationMsg("There are no effects", Pokemod::V_Warn); - for (int i = 0; i < getWidth(); ++i) + pokemod()->validationMsg("There are no effects", Pokemod::V_Warn); + for (int i = 0; i < width(); ++i) { - for (int j = 0; j < getHeight(); ++j) + for (int j = 0; j < height(); ++j) { - if (pokemod->getTileIndex(tiles(i, j)) == -1) + if (pokemod()->tileIndex(m_tiles(i, j)) == INT_MAX) { - pokemod->validationMsg(QString("Invalid tile at (%1, %2)").arg(i).arg(j)); + pokemod()->validationMsg(QString("Invalid tile at (%1, %2)").arg(i).arg(j)); valid = false; } } @@ -244,490 +185,514 @@ bool Map::validate() const return valid; } -int Map::getNewEffectId() const +void Map::load(const QString& fileName, int id) throw(Exception) { - int i = 0; - for (; (i < getEffectCount()) && (getEffectIndex(i) != -1); ++i) - ; - return i; -} - -int Map::getNewTrainerId() const -{ - int i = 0; - for (; (i < getTrainerCount()) && (getTrainerIndex(i) != -1); ++i) - ; - return i; -} - -int Map::getNewWarpId() const -{ - int i = 0; - for (; (i < getWarpCount()) && (getWarpIndex(i) != -1); ++i) - ; - return i; -} - -int Map::getNewWildListId() const -{ - int i = 0; - for (; (i < getWarpCount()) && (getWarpIndex(i) != -1); ++i) - ; - return i; -} - -void Map::load(const QString& fname, const int _id) throw(Exception) -{ - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); - ini.getValue("flyWarp", flyWarp); - ini.getValue("type", type); + ini.getValue("name", m_name); + ini.getValue("flyWarp", m_flyWarp); + ini.getValue("type", m_type); ini.getValue("width", i, 0); ini.getValue("height", j, 0); - tiles.resize(i, j, Frac(1, 1)); - for (int i = 0; i < getWidth(); ++i) + m_tiles.resize(i, j, Frac(1, 1)); + for (int i = 0; i < width(); ++i) { - for (int j = 0; j < getHeight(); ++j) - ini.getValue(QString("tiles-%1-%2").arg(i).arg(j), tiles(i, j)); + for (int j = 0; j < height(); ++j) + ini.getValue(QString("tiles-%1-%2").arg(i).arg(j), m_tiles(i, j)); } - QStringList path = pokemod->getPath().split('/'); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - effects.clear(); + QStringList files; + m_effects.clear(); if (fdir.cd("effect")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEffect(i.next()); + files = fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name); + foreach (QString file, files) + newEffect(file); fdir.cdUp(); } - trainers.clear(); + m_trainers.clear(); if (fdir.cd("trainer")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newTrainer(QString("%1/data.pini").arg(i.next())); + files = fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name); + foreach (QString file, files) + newTrainer(file); fdir.cdUp(); } - warps.clear(); + m_warps.clear(); if (fdir.cd("warp")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newWarp(i.next()); + files = fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name); + foreach (QString file, files) + newWarp(file); fdir.cdUp(); } - wildLists.clear(); + m_wildLists.clear(); if (fdir.cd("wildlist")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newWildList(QString("%1/data.pini").arg(i.next())); + files = fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name); + foreach (QString file, files) + newWildList(file); } } void Map::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("flyWarp", flyWarp); - ini.addField("type", type); - ini.addField("width", getWidth()); - ini.addField("height", getHeight()); - for (int i = 0; i < getWidth(); ++i) + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("flyWarp", m_flyWarp); + ini.addField("type", m_type); + ini.addField("width", width()); + ini.addField("height", height()); + for (int i = 0; i < width(); ++i) { - for (int j = 0; j < getWidth(); ++j) - ini.addField(QString("tiles-%1-%2").arg(i).arg(j), tiles(i, j)); + for (int j = 0; j < width(); ++j) + ini.addField(QString("tiles-%1-%2").arg(i).arg(j), m_tiles(i, j)); } - ini.save(QString("%1/map/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<MapEffect*> i(effects); i.hasNext(); ) - i.next()->save(name); - for (QListIterator<MapTrainer*> i(trainers); i.hasNext(); ) - i.next()->save(name); - for (QListIterator<MapWarp*> i(warps); i.hasNext(); ) - i.next()->save(name); - for (QListIterator<MapWildList*> i(wildLists); i.hasNext(); ) - i.next()->save(name); + ini.save(QString("%1/map/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (MapEffect* effect, m_effects) + effect->save(m_name); + foreach (MapTrainer* trainer, m_trainers) + trainer->save(m_name); + foreach (MapWarp* warp, m_warps) + warp->save(m_name); + foreach (MapWildList* wildList, m_wildLists) + wildList->save(m_name); } -void Map::setName(const QString& n) +void Map::setName(const QString& name) { - name = n; + m_name = name; } -void Map::setFlyWarp(const int f) throw(BoundsException) +void Map::setFlyWarp(const int warp) throw(BoundsException) { - if ((f != -1) && (getWarpIndex(f) == -1)) - throw(BoundsException(className, "warp")); - flyWarp = f; + if ((warp != INT_MAX) && (warpIndex(warp) == INT_MAX)) + throw(BoundsException(className(), "warp")); + m_flyWarp = warp; } -void Map::setType(const int t) throw(BoundsException) +void Map::setType(const int type) throw(BoundsException) { - if (End <= t) - throw(BoundsException(className, "type")); - type = t; + if (End <= type) + throw(BoundsException(className(), "type")); + m_type = type; } -QString Map::getName() const +QString Map::name() const { - return name; + return m_name; } -int Map::getFlyWarp() const +int Map::flyWarp() const { - return flyWarp; + return m_flyWarp; } -int Map::getType() const +int Map::type() const { - return type; + return m_type; } -void Map::setTile(int x, int y, int _id) throw(BoundsException) +void Map::setTile(int x, int y, int id) throw(BoundsException) { - if (pokemod->getTileIndex(_id) == -1) - throw(BoundsException(className, "tile")); - tiles(x, y) = _id; + if (pokemod()->tileIndex(id) == INT_MAX) + throw(BoundsException(className(), "tile")); + m_tiles(x, y) = id; } void Map::insertColumn(int x) { - tiles.insertCol(x, 0); + m_tiles.insertColumn(x, 0); } void Map::insertRow(int y) { - tiles.insertRow(y, 0); + m_tiles.insertRow(y, 0); } void Map::addColumn() { - tiles.addCol(0); + m_tiles.addColumn(0); } void Map::addRow() { - tiles.addRow(0); + m_tiles.addRow(0); } void Map::deleteColumn(int x) { - tiles.deleteCol(x); + m_tiles.deleteColumn(x); } void Map::deleteRow(int y) { - tiles.deleteRow(y); + m_tiles.deleteRow(y); } -const Matrix<int>* Map::getMap() const +const Matrix<int>* Map::map() const { - return &tiles; + return &m_tiles; } -Matrix<int>* Map::getMap() +Matrix<int>* Map::map() { - return &tiles; + return &m_tiles; } -int Map::getTile(int x, int y) const +int Map::tile(int x, int y) const { - return tiles(x, y); + return m_tiles(x, y); } -int Map::getWidth() const +int Map::width() const { - return tiles.getWidth(); + return m_tiles.width(); } -int Map::getHeight() const +int Map::height() const { - return tiles.getHeight(); + return m_tiles.height(); } -const MapEffect* Map::getEffect(const int i) const throw(IndexException) +const MapEffect* Map::effect(const int index) const throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects.at(i); + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects.at(index); } -MapEffect* Map::getEffect(const int i) throw(IndexException) +MapEffect* Map::effect(const int index) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects[i]; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects[index]; } -const MapEffect* Map::getEffectByID(const int i) const throw(IndexException) +const MapEffect* Map::effectById(const int index) const throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(index)); } -MapEffect* Map::getEffectByID(const int i) throw(IndexException) +MapEffect* Map::effectById(const int index) throw(IndexException) { - return getEffect(getEffectIndex(i)); + return effect(effectIndex(index)); } -int Map::getEffectIndex(const int _id) const +int Map::effectIndex(const int id) const { - for (int i = 0; i < getEffectCount(); ++i) + for (int i = 0; i < effectCount(); ++i) { - if (effects[i]->getId() == _id) + if (m_effects[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Map::getEffectCount() const +int Map::effectCount() const { - return effects.size(); + return m_effects.size(); } MapEffect* Map::newEffect() { - effects.append(new MapEffect(pokemod, getNewEffectId())); - return effects[getEffectCount() - 1]; + m_effects.append(new MapEffect(pokemod(), newEffectId())); + return m_effects[effectCount() - 1]; +} + +MapEffect* Map::newEffect(const QString& fileName) +{ + m_effects.append(new MapEffect(pokemod(), fileName, newEffectId())); + return m_effects[effectCount() - 1]; } -MapEffect* Map::newEffect(const QString& fname) +MapEffect* Map::newEffect(const MapEffect& effect) { - effects.append(new MapEffect(pokemod, fname, getNewEffectId())); - return effects[getEffectCount() - 1]; + m_effects.append(new MapEffect(pokemod(), effect, newEffectId())); + return m_effects[effectCount() - 1]; } -MapEffect* Map::newEffect(const MapEffect& e) +void Map::deleteEffect(const int index) throw(IndexException) { - effects.append(new MapEffect(pokemod, e, getNewEffectId())); - return effects[getEffectCount() - 1]; + if (effectCount() <= index) + throw(IndexException(className())); + delete m_effects[index]; + m_effects.removeAt(index); } -void Map::deleteEffect(const int i) throw(IndexException) +void Map::deleteEffectById(const int id) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - delete effects[i]; - effects.removeAt(i); + deleteEffect(effectIndex(id)); } -const MapTrainer* Map::getTrainer(const int i) const throw(IndexException) +int Map::newEffectId() const { - if (getTrainerCount() <= i) - throw(IndexException(className)); - return trainers.at(i); + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; } -MapTrainer* Map::getTrainer(const int i) throw(IndexException) +const MapTrainer* Map::trainer(const int index) const throw(IndexException) { - if (getTrainerCount() <= i) - throw(IndexException(className)); - return trainers[i]; + if (trainerCount() <= index) + throw(IndexException(className())); + return m_trainers.at(index); } -const MapTrainer* Map::getTrainerByID(const int i) const throw(IndexException) +MapTrainer* Map::trainer(const int index) throw(IndexException) { - return getTrainer(getTrainerIndex(i)); + if (trainerCount() <= index) + throw(IndexException(className())); + return m_trainers[index]; } -MapTrainer* Map::getTrainerByID(const int i) throw(IndexException) +const MapTrainer* Map::trainerById(const int id) const throw(IndexException) { - return getTrainer(getTrainerIndex(i)); + return trainer(trainerIndex(id)); } -int Map::getTrainerIndex(const int _id) const +MapTrainer* Map::trainerById(const int id) throw(IndexException) { - for (int i = 0; i < getTrainerCount(); ++i) + return trainer(trainerIndex(id)); +} + +int Map::trainerIndex(const int id) const +{ + for (int i = 0; i < trainerCount(); ++i) { - if (trainers[i]->getId() == _id) + if (m_trainers[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Map::getTrainerCount() const +int Map::trainerCount() const { - return trainers.size(); + return m_trainers.size(); } MapTrainer* Map::newTrainer() { - trainers.append(new MapTrainer(pokemod, getNewTrainerId())); - return trainers[getTrainerCount() - 1]; + m_trainers.append(new MapTrainer(pokemod(), newTrainerId())); + return m_trainers[trainerCount() - 1]; } -MapTrainer* Map::newTrainer(const QString& fname) +MapTrainer* Map::newTrainer(const QString& fileName) { - trainers.append(new MapTrainer(pokemod, fname, getNewTrainerId())); - return trainers[getTrainerCount() - 1]; + m_trainers.append(new MapTrainer(pokemod(), fileName, newTrainerId())); + return m_trainers[trainerCount() - 1]; } -MapTrainer* Map::newTrainer(const MapTrainer& t) +MapTrainer* Map::newTrainer(const MapTrainer& trainer) { - trainers.append(new MapTrainer(pokemod, t, getNewTrainerId())); - return trainers[getTrainerCount() - 1]; + m_trainers.append(new MapTrainer(pokemod(), trainer, newTrainerId())); + return m_trainers[trainerCount() - 1]; } -void Map::deleteTrainer(const int i) throw(IndexException) +void Map::deleteTrainer(const int index) throw(IndexException) { - if (getTrainerCount() <= i) - throw(IndexException(className)); - delete trainers[i]; - trainers.removeAt(i); + if (trainerCount() <= index) + throw(IndexException(className())); + delete m_trainers[index]; + m_trainers.removeAt(index); } -const MapWarp* Map::getWarp(const int i) const throw(IndexException) +void Map::deleteTrainerById(const int id) throw(IndexException) { - if (getWarpCount() <= i) - throw(IndexException(className)); - return warps.at(i); + deleteTrainer(trainerIndex(id)); } -MapWarp* Map::getWarp(const int i) throw(IndexException) +int Map::newTrainerId() const { - if (getWarpCount() <= i) - throw(IndexException(className)); - return warps[i]; + int i = 0; + while ((i < trainerCount()) && (trainerIndex(i) != INT_MAX)) + ++i; + return i; } -const MapWarp* Map::getWarpByID(const int i) const throw(IndexException) +const MapWarp* Map::warp(const int index) const throw(IndexException) { - return getWarp(getWarpIndex(i)); + if (warpCount() <= index) + throw(IndexException(className())); + return m_warps.at(index); } -MapWarp* Map::getWarpByID(const int i) throw(IndexException) +MapWarp* Map::warp(const int index) throw(IndexException) { - return getWarp(getWarpIndex(i)); + if (warpCount() <= index) + throw(IndexException(className())); + return m_warps[index]; } -int Map::getWarpIndex(const int _id) const +const MapWarp* Map::warpById(const int id) const throw(IndexException) { - for (int i = 0; i < getWarpCount(); ++i) + return warp(warpIndex(id)); +} + +MapWarp* Map::warpById(const int id) throw(IndexException) +{ + return warp(warpIndex(id)); +} + +int Map::warpIndex(const int id) const +{ + for (int i = 0; i < warpCount(); ++i) { - if (warps[i]->getId() == _id) + if (m_warps[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Map::getWarpCount() const +int Map::warpCount() const { - return warps.size(); + return m_warps.size(); } MapWarp* Map::newWarp() { - warps.append(new MapWarp(pokemod, getNewWarpId())); - return warps[getWarpCount() - 1]; + m_warps.append(new MapWarp(pokemod(), newWarpId())); + return m_warps[warpCount() - 1]; +} + +MapWarp* Map::newWarp(const QString& fileName) +{ + m_warps.append(new MapWarp(pokemod(), fileName, newWarpId())); + return m_warps[warpCount() - 1]; +} + +MapWarp* Map::newWarp(const MapWarp& warp) +{ + m_warps.append(new MapWarp(pokemod(), warp, newWarpId())); + return m_warps[warpCount() - 1]; } -MapWarp* Map::newWarp(const QString& fname) +void Map::deleteWarp(const int index) throw(IndexException) { - warps.append(new MapWarp(pokemod, fname, getNewWarpId())); - return warps[getWarpCount() - 1]; + if (warpCount() <= index) + throw(IndexException(className())); + delete m_warps[index]; + m_warps.removeAt(index); } -MapWarp* Map::newWarp(const MapWarp& w) +void Map::deleteWarpById(const int id) throw(IndexException) { - warps.append(new MapWarp(pokemod, w, getNewWarpId())); - return warps[getWarpCount() - 1]; + deleteWarp(warpIndex(id)); } -void Map::deleteWarp(const int i) throw(IndexException) +int Map::newWarpId() const { - if (getWarpCount() <= i) - throw(IndexException(className)); - delete warps[i]; - warps.removeAt(i); + int i = 0; + while ((i < warpCount()) && (warpIndex(i) != INT_MAX)) + ++i; + return i; } -const MapWildList* Map::getWildList(const int i) const throw(IndexException) +const MapWildList* Map::wildList(const int index) const throw(IndexException) { - if (getWildListCount() <= i) - throw(IndexException(className)); - return wildLists.at(i); + if (wildListCount() <= index) + throw(IndexException(className())); + return m_wildLists.at(index); } -MapWildList* Map::getWildList(const int i) throw(IndexException) +MapWildList* Map::wildList(const int index) throw(IndexException) { - if (getWildListCount() <= i) - throw(IndexException(className)); - return wildLists[i]; + if (wildListCount() <= index) + throw(IndexException(className())); + return m_wildLists[index]; } -const MapWildList* Map::getWildListByID(const int i) const throw(IndexException) +const MapWildList* Map::wildListById(const int id) const throw(IndexException) { - return getWildList(getWildListIndex(i)); + return wildList(wildListIndex(id)); } -MapWildList* Map::getWildListByID(const int i) throw(IndexException) +MapWildList* Map::wildListById(const int id) throw(IndexException) { - return getWildList(getWildListIndex(i)); + return wildList(wildListIndex(id)); } -int Map::getWildListIndex(const int _id) const +int Map::wildListIndex(const int id) const { - for (int i = 0; i < getWildListCount(); ++i) + for (int i = 0; i < wildListCount(); ++i) { - if (wildLists[i]->getId() == _id) + if (m_wildLists[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Map::getWildListCount() const +int Map::wildListCount() const { - return wildLists.size(); + return m_wildLists.size(); } MapWildList* Map::newWildList() { - wildLists.append(new MapWildList(pokemod, getNewWildListId())); - return wildLists[getWildListCount() - 1]; + m_wildLists.append(new MapWildList(pokemod(), newWildListId())); + return m_wildLists[wildListCount() - 1]; +} + +MapWildList* Map::newWildList(const QString& fileName) +{ + m_wildLists.append(new MapWildList(pokemod(), fileName, newWildListId())); + return m_wildLists[wildListCount() - 1]; } -MapWildList* Map::newWildList(const QString& fname) +MapWildList* Map::newWildList(const MapWildList& wildList) { - wildLists.append(new MapWildList(pokemod, fname, getNewWildListId())); - return wildLists[getWildListCount() - 1]; + m_wildLists.append(new MapWildList(pokemod(), wildList, newWildListId())); + return m_wildLists[wildListCount() - 1]; } -MapWildList* Map::newWildList(const MapWildList& w) +void Map::deleteWildList(const int index) throw(IndexException) { - wildLists.append(new MapWildList(pokemod, w, getNewWildListId())); - return wildLists[getWildListCount() - 1]; + if (wildListCount() <= index) + throw(IndexException(className())); + delete m_wildLists[index]; + m_wildLists.removeAt(index); } -void Map::deleteWildList(const int i) throw(IndexException) +void Map::deleteWildListById(const int id) throw(IndexException) { - if (getWildListCount() <= i) - throw(IndexException(className)); - delete wildLists[i]; - wildLists.removeAt(i); + deleteWildList(wildListIndex(id)); +} + +int Map::newWildListId() const +{ + int i = 0; + while ((i < warpCount()) && (warpIndex(i) != INT_MAX)) + ++i; + return i; } Map& Map::operator=(const Map& rhs) { if (this == &rhs) return *this; - name = rhs.name; - flyWarp = rhs.flyWarp; - type = rhs.type; - tiles = rhs.tiles; - effects.clear(); - for (int i = 0; i < rhs.getEffectCount(); ++i) - effects.append(new MapEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); - trainers.clear(); - for (int i = 0; i < rhs.getTrainerCount(); ++i) - trainers.append(new MapTrainer(pokemod, *rhs.getTrainer(i), rhs.getTrainer(i)->getId())); - warps.clear(); - for (int i = 0; i < rhs.getWarpCount(); ++i) - warps.append(new MapWarp(pokemod, *rhs.getWarp(i), rhs.getWarp(i)->getId())); - wildLists.clear(); - for (int i = 0; i < rhs.getWildListCount(); ++i) - wildLists.append(new MapWildList(pokemod, *rhs.getWildList(i), rhs.getWildList(i)->getId())); + m_name = rhs.m_name; + m_flyWarp = rhs.m_flyWarp; + m_type = rhs.m_type; + m_tiles = rhs.m_tiles; + m_effects.clear(); + foreach (MapEffect* effect, rhs.m_effects) + m_effects.append(new MapEffect(pokemod(), *effect, effect->id())); + m_trainers.clear(); + foreach (MapTrainer* trainer, rhs.m_trainers) + m_trainers.append(new MapTrainer(pokemod(), *trainer, trainer->id())); + m_warps.clear(); + foreach (MapWarp* warp, rhs.m_warps) + m_warps.append(new MapWarp(pokemod(), *warp, warp->id())); + m_wildLists.clear(); + foreach (MapWildList* wildList, rhs.m_wildLists) + m_wildLists.append(new MapWildList(pokemod(), *wildList, wildList->id())); return *this; } diff --git a/pokemod/Map.h b/pokemod/Map.h index 2acc5b84..79ccf9e8 100644 --- a/pokemod/Map.h +++ b/pokemod/Map.h @@ -1,37 +1,36 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Map.h -// Purpose: Define a map for the game -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Mon May 28 2007 21:41:54 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Matrix.h> +// Pokemod includes #include "Object.h" +// Forward declarations class MapEffect; class MapTrainer; class MapWarp; @@ -50,23 +49,23 @@ class Map : public Object }; static const QStringList TypeStr; - Map(const Pokemod* par, const int _id); - Map(const Pokemod* par, const Map& m, const int _id); - Map(const Pokemod* par, const QString& fname, const int _id = -1); + Map(const Pokemod* pokemod, const int id); + Map(const Pokemod* pokemod, const Map& map, const int id); + Map(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~Map(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setFlyWarp(const int f) throw(BoundsException); - void setType(const int t) throw(BoundsException); + void setName(const QString& name); + void setFlyWarp(const int warp) throw(BoundsException); + void setType(const int type) throw(BoundsException); - QString getName() const; - int getFlyWarp() const; - int getType() const; + QString name() const; + int flyWarp() const; + int type() const; - void setTile(int x, int y, int _id) throw(BoundsException); + void setTile(int x, int y, int id) throw(BoundsException); void insertColumn(int x); void insertRow(int y); void addColumn(); @@ -74,73 +73,77 @@ class Map : public Object void deleteColumn(int x); void deleteRow(int y); - const Matrix<int>* getMap() const; - Matrix<int>* getMap(); - int getTile(int x, int y) const; - int getWidth() const; - int getHeight() const; + const Matrix<int>* map() const; + Matrix<int>* map(); + int tile(int x, int y) const; + int width() const; + int height() const; - const MapEffect* getEffect(const int i) const throw(IndexException); - MapEffect* getEffect(const int i) throw(IndexException); - const MapEffect* getEffectByID(const int i) const throw(IndexException); - MapEffect* getEffectByID(const int i) throw(IndexException); - int getEffectIndex(const int _id) const; - int getEffectCount() const; + const MapEffect* effect(const int index) const throw(IndexException); + MapEffect* effect(const int index) throw(IndexException); + const MapEffect* effectById(const int id) const throw(IndexException); + MapEffect* effectById(const int id) throw(IndexException); + int effectIndex(const int id) const; + int effectCount() const; MapEffect* newEffect(); - MapEffect* newEffect(const QString& fname); - MapEffect* newEffect(const MapEffect& e); - void deleteEffect(const int i) throw(IndexException); + MapEffect* newEffect(const QString& fileName); + MapEffect* newEffect(const MapEffect& effect); + void deleteEffect(const int index) throw(IndexException); + void deleteEffectById(const int id) throw(IndexException); - const MapTrainer* getTrainer(const int i) const throw(IndexException); - MapTrainer* getTrainer(const int i) throw(IndexException); - const MapTrainer* getTrainerByID(const int i) const throw(IndexException); - MapTrainer* getTrainerByID(const int i) throw(IndexException); - int getTrainerIndex(const int _id) const; - int getTrainerCount() const; + const MapTrainer* trainer(const int index) const throw(IndexException); + MapTrainer* trainer(const int index) throw(IndexException); + const MapTrainer* trainerById(const int id) const throw(IndexException); + MapTrainer* trainerById(const int id) throw(IndexException); + int trainerIndex(const int id) const; + int trainerCount() const; MapTrainer* newTrainer(); - MapTrainer* newTrainer(const QString& fname); - MapTrainer* newTrainer(const MapTrainer& t); - void deleteTrainer(const int i) throw(IndexException); + MapTrainer* newTrainer(const QString& fileName); + MapTrainer* newTrainer(const MapTrainer& trainer); + void deleteTrainer(const int index) throw(IndexException); + void deleteTrainerById(const int id) throw(IndexException); - const MapWarp* getWarp(const int i) const throw(IndexException); - MapWarp* getWarp(const int i) throw(IndexException); - const MapWarp* getWarpByID(const int i) const throw(IndexException); - MapWarp* getWarpByID(const int i) throw(IndexException); - int getWarpIndex(const int _id) const; - int getWarpCount() const; + const MapWarp* warp(const int index) const throw(IndexException); + MapWarp* warp(const int index) throw(IndexException); + const MapWarp* warpById(const int id) const throw(IndexException); + MapWarp* warpById(const int id) throw(IndexException); + int warpIndex(const int id) const; + int warpCount() const; MapWarp* newWarp(); - MapWarp* newWarp(const QString& fname); - MapWarp* newWarp(const MapWarp& w); - void deleteWarp(const int i) throw(IndexException); + MapWarp* newWarp(const QString& fileName); + MapWarp* newWarp(const MapWarp& warp); + void deleteWarp(const int index) throw(IndexException); + void deleteWarpById(const int id) throw(IndexException); - const MapWildList* getWildList(const int i) const throw(IndexException); - MapWildList* getWildList(const int i) throw(IndexException); - const MapWildList* getWildListByID(const int i) const throw(IndexException); - MapWildList* getWildListByID(const int i) throw(IndexException); - int getWildListIndex(const int _id) const; - int getWildListCount() const; + const MapWildList* wildList(const int index) const throw(IndexException); + MapWildList* wildList(const int index) throw(IndexException); + const MapWildList* wildListById(const int id) const throw(IndexException); + MapWildList* wildListById(const int id) throw(IndexException); + int wildListIndex(const int id) const; + int wildListCount() const; MapWildList* newWildList(); - MapWildList* newWildList(const QString& fname); - MapWildList* newWildList(const MapWildList& w); - void deleteWildList(const int i) throw(IndexException); + MapWildList* newWildList(const QString& fileName); + MapWildList* newWildList(const MapWildList& wildList); + void deleteWildList(const int index) throw(IndexException); + void deleteWildListById(const int id) throw(IndexException); Map& operator=(const Map& rhs); private: bool validate() const; - int getNewEffectId() const; - int getNewTrainerId() const; - int getNewWarpId() const; - int getNewWildListId() const; + int newEffectId() const; + int newTrainerId() const; + int newWarpId() const; + int newWildListId() const; - QString name; - int flyWarp; - int type; - Matrix<int> tiles; + QString m_name; + int m_flyWarp; + int m_type; + Matrix<int> m_tiles; - QList<MapEffect*> effects; - QList<MapTrainer*> trainers; - QList<MapWarp*> warps; - QList<MapWildList*> wildLists; + QList<MapEffect*> m_effects; + QList<MapTrainer*> m_trainers; + QList<MapWarp*> m_warps; + QList<MapWildList*> m_wildLists; }; #endif diff --git a/pokemod/MapEffect.cpp b/pokemod/MapEffect.cpp index 484e304f..f18c54e5 100644 --- a/pokemod/MapEffect.cpp +++ b/pokemod/MapEffect.cpp @@ -1,343 +1,320 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapEffect.cpp -// Purpose: Define an effect for a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 20:23:15 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Pokemod includes #include "Pokemod.h" #include "Dialog.h" + +// Header include #include "MapEffect.h" const QStringList MapEffect::MapEffectStr = QStringList() << "Item" << "PC" << "Strength Block" << "Button" << "Slot Machine" << "Card Flip Game"; const QStringList MapEffect::PCTypeStr = QStringList() << "Item" << "Pokémon" << "PokéDex" << "Hall of Fame" << "All"; -MapEffect::MapEffect(const Pokemod* par, const int _id) : - Object("MapEffect", par, _id), - name(""), - coordinate(0, 0), - existFlag(0, 0), - skin(""), - effect(-1), - val1(-1), - val2(-1), - direction(-1), - isGhost(false), - canMove(false), - dialog(-1) +MapEffect::MapEffect(const Pokemod* pokemod, const int id) : + Object("MapEffect", pokemod, id), + m_name(""), + m_coordinate(0, 0), + m_existFlag(0, 0), + m_skin(""), + m_effect(INT_MAX), + m_value1(INT_MAX), + m_value2(INT_MAX), + m_direction(INT_MAX), + m_isGhost(false), + m_canMove(false), + m_dialog(INT_MAX) { } -MapEffect::MapEffect(const Pokemod* par, const MapEffect& e, const int _id) : - Object("MapEffect", par, _id) +MapEffect::MapEffect(const Pokemod* pokemod, const MapEffect& effect, const int id) : + Object("MapEffect", pokemod, id) { - *this = e; + *this = effect; } -MapEffect::MapEffect(const Pokemod* par, const QString& fname, const int _id) : - Object("MapEffect", par, _id) +MapEffect::MapEffect(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapEffect", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MapEffect::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Effect \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("------Effect \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (Flag::End <= existFlag.getStatus()) + if (Flag::End <= m_existFlag.status()) { - pokemod->validationMsg("Invalid existence flag status"); + pokemod()->validationMsg("Invalid existence flag status"); valid = false; } - if (!QFile::exists(getSkin())) + if (!QFile::exists(skin())) { - pokemod->validationMsg(QString("Skin not found")); + pokemod()->validationMsg(QString("Skin not found")); valid = false; } - if (effect < E_End) + if (m_effect < E_End) { bool ok = true; - switch (effect) + switch (m_effect) { case E_Item: - if (pokemod->getItemIndex(val2) == -1) + if (pokemod()->itemIndex(m_value2) == INT_MAX) ok = false; break; case E_PC: - if (PC_End <= val2) + if (PC_End <= m_value2) ok = false; break; case E_StrengthBlock: case E_Button: - if (Flag::End <= val2) + if (Flag::End <= m_value2) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid val2"); + pokemod()->validationMsg("Invalid val2"); valid = false; } } else { - pokemod->validationMsg("Invalid effect"); + pokemod()->validationMsg("Invalid effect"); valid = false; } - if (Pokemod::D_End_None <= direction) + if (Pokemod::D_End_None <= m_direction) { - pokemod->validationMsg("Invalid driection"); + pokemod()->validationMsg("Invalid driection"); valid = false; } - if (pokemod->getDialogIndex(dialog) == -1) + if (pokemod()->dialogIndex(m_dialog) == INT_MAX) { - pokemod->validationMsg("Invalid dialog"); + pokemod()->validationMsg("Invalid dialog"); valid = false; } return valid; } -void MapEffect::load(const QString& fname, const int _id) throw(Exception) +void MapEffect::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); ini.getValue("coordinate-x", i, 0); ini.getValue("coordinate-y", j, 0); - coordinate.set(i, j); + m_coordinate.set(i, j); ini.getValue("existFlag-f", i, 0); ini.getValue("existFlag-s", j, 0); - existFlag.set(i, j); - ini.getValue("skin", skin); - ini.getValue("effect", effect); - ini.getValue("val1", val1); - ini.getValue("val2", val2); - ini.getValue("direction", direction); - ini.getValue("isGhost", isGhost); - ini.getValue("canMove", canMove); - ini.getValue("dialog", dialog); + m_existFlag.set(i, j); + ini.getValue("skin", m_skin); + ini.getValue("effect", m_effect); + ini.getValue("val1", m_value1); + ini.getValue("val2", m_value2); + ini.getValue("direction", m_direction); + ini.getValue("isGhost", m_isGhost); + ini.getValue("canMove", m_canMove); + ini.getValue("dialog", m_dialog); } void MapEffect::save(const QString& map) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("coordinate-x", coordinate.getX()); - ini.addField("coordinate-y", coordinate.getY()); - ini.addField("existFlag-f", existFlag.getFlag()); - ini.addField("existFlag-s", existFlag.getStatus()); - ini.addField("skin", skin); - ini.addField("effect", effect); - ini.addField("val1", val1); - ini.addField("val2", val2); - ini.addField("direction", direction); - ini.addField("isGhost", isGhost); - ini.addField("canMove", canMove); - ini.addField("dialog", dialog); - ini.save(QString("%1/map/%2/effect/%3.pini").arg(pokemod->getPath()).arg(map).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("coordinate-x", m_coordinate.x()); + ini.addField("coordinate-y", m_coordinate.y()); + ini.addField("existFlag-f", m_existFlag.flag()); + ini.addField("existFlag-s", m_existFlag.status()); + ini.addField("skin", m_skin); + ini.addField("effect", m_effect); + ini.addField("val1", m_value1); + ini.addField("val2", m_value2); + ini.addField("direction", m_direction); + ini.addField("isGhost", m_isGhost); + ini.addField("canMove", m_canMove); + ini.addField("dialog", m_dialog); + ini.save(QString("%1/map/%2/effect/%3.pini").arg(pokemod()->path()).arg(map).arg(m_name)); } -void MapEffect::setName(const QString& n) +void MapEffect::setName(const QString& name) { - name = n; + m_name = name; } void MapEffect::setCoordinate(const int x, const int y) { - coordinate.set(x, y); + m_coordinate.set(x, y); } -void MapEffect::setCoordinateX(const int x) +void MapEffect::setExistFlag(const int flag, const int status) { - coordinate.setX(x); + m_existFlag.set(flag, status); } -void MapEffect::setCoordinateY(const int y) +void MapEffect::setSkin(const QString& skin) throw(Exception) { - coordinate.setY(y); + if (!QFile::exists(QString("%1/image/skin/%2.png").arg(pokemod()->path()).arg(skin))) + throw(Exception(className(), "skin does not exist")); + m_skin = skin; } -void MapEffect::setExistFlag(const int f, const int s) +void MapEffect::setEffect(const int effect) throw(BoundsException) { - existFlag.set(f, s); + if (E_End <= effect) + throw(BoundsException(className(), "effect")); + m_effect = effect; + m_value1 = INT_MAX; + m_value2 = INT_MAX; } -void MapEffect::setExistFlagFlag(const int f) +void MapEffect::setValue1(const int value1) throw(UnusedException) { - existFlag.setFlag(f); + if ((m_effect != E_StrengthBlock) && (m_effect != E_Button)) + throw(UnusedException(className(), "val1")); + m_value1 = value1; } -void MapEffect::setExistFlagStatus(const int s) +void MapEffect::setValue2(const int value2) throw(Exception) { - existFlag.setStatus(s); -} - -void MapEffect::setSkin(const QString& s) throw(Exception) -{ - if (!QFile::exists(QString("%1/image/skin/%2.png").arg(pokemod->getPath()).arg(s))) - throw(Exception(className, "skin does not exist")); - skin = s; -} - -void MapEffect::setEffect(const int e) throw(BoundsException) -{ - if (E_End <= e) - throw(BoundsException(className, "effect")); - effect = e; - val1 = -1; - val2 = -1; -} - -void MapEffect::setVal1(const int v1) throw(UnusedException) -{ - if ((effect != E_StrengthBlock) && (effect != E_Button)) - throw(UnusedException(className, "val1")); - val1 = v1; -} - -void MapEffect::setVal2(const int v2) throw(Exception) -{ - switch (effect) + switch (m_effect) { case E_Item: - if (pokemod->getItemIndex(val2) == -1) - throw(BoundsException(className, "val2")); + if (pokemod()->itemIndex(value2) == INT_MAX) + throw(BoundsException(className(), "val2")); break; case E_PC: - if (PC_End <= val2) - throw(BoundsException(className, "val2")); + if (PC_End <= value2) + throw(BoundsException(className(), "val2")); break; case E_StrengthBlock: case E_Button: - if (Flag::End <= val2) - throw(BoundsException(className, "val2")); + if (Flag::End <= value2) + throw(BoundsException(className(), "val2")); break; default: - throw(UnusedException(className, "val2")); + throw(UnusedException(className(), "val2")); break; } - val2 = v2; + m_value2 = value2; } -void MapEffect::setDirection(const int d) throw(BoundsException) +void MapEffect::setDirection(const int direction) throw(BoundsException) { - if (Pokemod::D_End_None <= d) - throw(BoundsException(className, "direction")); - direction = d; + if (Pokemod::D_End_None <= direction) + throw(BoundsException(className(), "direction")); + m_direction = direction; } -void MapEffect::setIsGhost(const bool i) +void MapEffect::setIsGhost(const bool isGhost) { - isGhost = i; + m_isGhost = isGhost; } -void MapEffect::setCanMove(const bool c) +void MapEffect::setCanMove(const bool canMove) { - canMove = c; + m_canMove = canMove; } -void MapEffect::setDialog(const int d) throw(BoundsException) +void MapEffect::setDialog(const int dialog) throw(BoundsException) { - if (pokemod->getDialogIndex(d) == -1) - throw(BoundsException(className, "dialog")); - dialog = d; + if (pokemod()->dialogIndex(dialog) == INT_MAX) + throw(BoundsException(className(), "dialog")); + m_dialog = dialog; } -QString MapEffect::getName() const +QString MapEffect::name() const { - return name; + return m_name; } -Point MapEffect::getCoordinate() const +Point MapEffect::coordinate() const { - return coordinate; + return m_coordinate; } -Flag MapEffect::getExistFlag() const +Flag MapEffect::existFlag() const { - return existFlag; + return m_existFlag; } -QString MapEffect::getSkin() const +QString MapEffect::skin() const { - return QString("%1/image/skin/%2.png").arg(pokemod->getPath()).arg(skin); + return QString("%1/image/skin/%2.png").arg(pokemod()->path()).arg(m_skin); } -int MapEffect::getEffect() const +int MapEffect::effect() const { - return effect; + return m_effect; } -int MapEffect::getVal1() const +int MapEffect::value1() const { - return val1; + return m_value1; } -int MapEffect::getVal2() const +int MapEffect::value2() const { - return val2; + return m_value2; } -int MapEffect::getDirection() const +int MapEffect::direction() const { - return direction; + return m_direction; } -bool MapEffect::getIsGhost() const +bool MapEffect::isGhost() const { - return isGhost; + return m_isGhost; } -bool MapEffect::getCanMove() const +bool MapEffect::canMove() const { - return canMove; + return m_canMove; } -int MapEffect::getDialog() const +int MapEffect::dialog() const { - return dialog; + return m_dialog; } MapEffect& MapEffect::operator=(const MapEffect& rhs) { if (this == &rhs) return *this; - name = rhs.name; - coordinate = rhs.coordinate; - existFlag = rhs.existFlag; - skin = rhs.skin; - effect = rhs.effect; - val1 = rhs.val1; - val2 = rhs.val2; - direction = rhs.direction; - isGhost = rhs.isGhost; - canMove = rhs.canMove; - dialog = rhs.dialog; + m_name = rhs.m_name; + m_coordinate = rhs.m_coordinate; + m_existFlag = rhs.m_existFlag; + m_skin = rhs.m_skin; + m_effect = rhs.m_effect; + m_value1 = rhs.m_value1; + m_value2 = rhs.m_value2; + m_direction = rhs.m_direction; + m_isGhost = rhs.m_isGhost; + m_canMove = rhs.m_canMove; + m_dialog = rhs.m_dialog; return *this; } diff --git a/pokemod/MapEffect.h b/pokemod/MapEffect.h index 36ef60b8..d72087b7 100644 --- a/pokemod/MapEffect.h +++ b/pokemod/MapEffect.h @@ -1,37 +1,36 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapEffect.h -// Purpose: Define an effect on a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 19:57:47 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Flag.h> #include <Point.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class MapEffect : public Object @@ -60,56 +59,52 @@ class MapEffect : public Object }; static const QStringList PCTypeStr; - MapEffect(const Pokemod* par, const int _id); - MapEffect(const Pokemod* par, const MapEffect& e, const int _id); - MapEffect(const Pokemod* par, const QString& fname, const int _id = -1); + MapEffect(const Pokemod* pokemod, const int id); + MapEffect(const Pokemod* pokemod, const MapEffect& effect, const int id); + MapEffect(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& map) const throw(Exception); - void setName(const QString& n); + void setName(const QString& name); void setCoordinate(const int x, const int y); - void setCoordinateX(const int x); - void setCoordinateY(const int y); - void setExistFlag(const int f, const int s); - void setExistFlagFlag(const int f); - void setExistFlagStatus(const int s); - void setSkin(const QString& s) throw(Exception); - void setEffect(const int e) throw(BoundsException); - void setVal1(const int v1) throw(UnusedException); - void setVal2(const int v2) throw(Exception); - void setDirection(const int d) throw(BoundsException); - void setIsGhost(const bool i); - void setCanMove(const bool c); - void setDialog(const int d) throw(BoundsException); + void setExistFlag(const int flag, const int status); + void setSkin(const QString& skin) throw(Exception); + void setEffect(const int effect) throw(BoundsException); + void setValue1(const int value1) throw(UnusedException); + void setValue2(const int value2) throw(Exception); + void setDirection(const int direction) throw(BoundsException); + void setIsGhost(const bool isGhost); + void setCanMove(const bool canMove); + void setDialog(const int dialog) throw(BoundsException); - QString getName() const; - Point getCoordinate() const; - Flag getExistFlag() const; - QString getSkin() const; - int getEffect() const; - int getVal1() const; - int getVal2() const; - int getDirection() const; - bool getIsGhost() const; - bool getCanMove() const; - int getDialog() const; + QString name() const; + Point coordinate() const; + Flag existFlag() const; + QString skin() const; + int effect() const; + int value1() const; + int value2() const; + int direction() const; + bool isGhost() const; + bool canMove() const; + int dialog() const; MapEffect& operator=(const MapEffect& rhs); private: bool validate() const; - QString name; - Point coordinate; - Flag existFlag; - QString skin; - int effect; - int val1; - int val2; - int direction; - bool isGhost; - bool canMove; - int dialog; + QString m_name; + Point m_coordinate; + Flag m_existFlag; + QString m_skin; + int m_effect; + int m_value1; + int m_value2; + int m_direction; + bool m_isGhost; + bool m_canMove; + int m_dialog; }; #endif diff --git a/pokemod/MapTrainer.cpp b/pokemod/MapTrainer.cpp index ae9e5585..dbcae301 100644 --- a/pokemod/MapTrainer.cpp +++ b/pokemod/MapTrainer.cpp @@ -1,393 +1,365 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapTrainer.cpp -// Purpose: Define a trainer for a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 23:11:28 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> #include <QStringList> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "Dialog.h" #include "MapTrainerTeamMember.h" + +// Header include #include "MapTrainer.h" -MapTrainer::MapTrainer(const Pokemod* par, const int _id) : - Object("MapTrainer", par, _id), - name(""), - trainerClass(-1), - coordinate(0, 0), - sight(0), - direction(-1), - numFight(1), - appearFlag(0, 0), - dialog(-1), - leadTeamMember(-1) +MapTrainer::MapTrainer(const Pokemod* pokemod, const int id) : + Object("MapTrainer", pokemod, id), + m_name(""), + m_trainerClass(INT_MAX), + m_coordinate(0, 0), + m_sight(0), + m_direction(INT_MAX), + m_numFight(1), + m_appearFlag(0, 0), + m_dialog(INT_MAX), + m_leadTeamMember(INT_MAX) { } -MapTrainer::MapTrainer(const Pokemod* par, const MapTrainer& t, const int _id) : - Object("MapTrainer", par, _id) +MapTrainer::MapTrainer(const Pokemod* pokemod, const MapTrainer& trainer, const int id) : + Object("MapTrainer", pokemod, id) { - *this = t; + *this = trainer; } -MapTrainer::MapTrainer(const Pokemod* par, const QString& fname, const int _id) : - Object("MapTrainer", par, _id) +MapTrainer::MapTrainer(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapTrainer", pokemod, id) { - load(fname, _id); + load(fileName, id); } MapTrainer::~MapTrainer() { - for (QListIterator<MapTrainerTeamMember*> i(teamMembers); i.hasNext(); ) - delete i.next(); + foreach (MapTrainerTeamMember* teamMember, m_teamMembers) + delete teamMember; } bool MapTrainer::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Trainer \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("------Trainer \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (pokemod->getTrainerIndex(trainerClass) == -1) + if (pokemod()->trainerIndex(m_trainerClass) == INT_MAX) { - pokemod->validationMsg("Invalid trainer class"); + pokemod()->validationMsg("Invalid trainer class"); valid = false; } - if (Pokemod::D_End_None <= direction) + if (Pokemod::D_End_None <= m_direction) { - pokemod->validationMsg("Invalid direction"); + pokemod()->validationMsg("Invalid direction"); valid = false; } - if (!numFight || (pokemod->getRules()->getMaxFight() < numFight)) + if (!m_numFight || (pokemod()->rules()->maxFight() < m_numFight)) { - pokemod->validationMsg("Invalid number of Pokémon for a fight"); + pokemod()->validationMsg("Invalid number of Pokémon for a fight"); valid = false; } - if (pokemod->getDialogIndex(dialog) == -1) + if (pokemod()->dialogIndex(m_dialog) == INT_MAX) { - pokemod->validationMsg("Invalid dialog"); + pokemod()->validationMsg("Invalid dialog"); valid = false; } - if (getTeamMemberCount() <= leadTeamMember) + if (teamMemberCount() <= m_leadTeamMember) { - pokemod->validationMsg("Invalid lead member"); + pokemod()->validationMsg("Invalid lead member"); valid = false; } - if (getTeamMemberCount()) + if (teamMemberCount()) { - QMap<int, int> idChecker; - for (QListIterator<MapTrainerTeamMember*> i(teamMembers); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + foreach (MapTrainerTeamMember* teamMember, m_teamMembers) { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 team members with id %2").arg(i.value()).arg(i.key())); + if (!teamMember->isValid()) valid = false; - } + if (idChecker[teamMember->id()]) + pokemod()->validationMsg(QString("Duplicate team member with id %1").arg(teamMember->id())); + idChecker[teamMember->id()] = true; } } else { - pokemod->validationMsg("There are no team members"); + pokemod()->validationMsg("There are no team members"); valid = false; } return valid; } -int MapTrainer::getNewId() const +void MapTrainer::load(const QString& fileName, int id) throw(Exception) { - int i = 0; - for (; i < getTeamMemberCount(); ++i) - { - if (getTeamMemberIndex(i) == -1) - return i; - } - return -1; -} - -void MapTrainer::load(const QString& fname, const int _id) throw(Exception) -{ - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); - ini.getValue("trainerClass", trainerClass); + ini.getValue("name", m_name); + ini.getValue("trainerClass", m_trainerClass); ini.getValue("coordinate-x", i, 0); ini.getValue("coordinate-y", j, 0); - coordinate.set(i, j); - ini.getValue("sight", sight, 0); - ini.getValue("direction", direction); - ini.getValue("numFight", numFight, 1); + m_coordinate.set(i, j); + ini.getValue("sight", m_sight, 0); + ini.getValue("direction", m_direction); + ini.getValue("numFight", m_numFight, 1); ini.getValue("appearFlag-f", i, 0); ini.getValue("appearFlag-s", j, 0); - appearFlag.set(i, j); - ini.getValue("dialog", dialog); - ini.getValue("leadTeamMember", leadTeamMember); - QStringList path = pokemod->getPath().split('/'); + m_appearFlag.set(i, j); + ini.getValue("dialog", m_dialog); + ini.getValue("leadTeamMember", m_leadTeamMember); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - teamMembers.clear(); + m_teamMembers.clear(); if (fdir.cd("team")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newTeamMember(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newTeamMember(file); } } void MapTrainer::save(const QString& map) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("trainerClass", trainerClass); - ini.addField("coordinate-x", coordinate.getX()); - ini.addField("coordinate-y", coordinate.getY()); - ini.addField("sight", sight); - ini.addField("direction", direction); - ini.addField("numFight", numFight); - ini.addField("appearFlag-f", appearFlag.getFlag()); - ini.addField("appearFlag-s", appearFlag.getStatus()); - ini.addField("dialog", dialog); - ini.addField("leadTeamMember", leadTeamMember); - ini.save(QString("%1/map/%2/trainer/%3/data.pini").arg(pokemod->getPath()).arg(map).arg(name)); - for (QListIterator<MapTrainerTeamMember*> i(teamMembers); i.hasNext(); ) - i.next()->save(map, name); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("trainerClass", m_trainerClass); + ini.addField("coordinate-x", m_coordinate.x()); + ini.addField("coordinate-y", m_coordinate.y()); + ini.addField("sight", m_sight); + ini.addField("direction", m_direction); + ini.addField("numFight", m_numFight); + ini.addField("appearFlag-f", m_appearFlag.flag()); + ini.addField("appearFlag-s", m_appearFlag.status()); + ini.addField("dialog", m_dialog); + ini.addField("leadTeamMember", m_leadTeamMember); + ini.save(QString("%1/map/%2/trainer/%3/data.pini").arg(pokemod()->path()).arg(map).arg(m_name)); + foreach (MapTrainerTeamMember* teamMember, m_teamMembers) + teamMember->save(map, m_name); } -void MapTrainer::setName(const QString& n) +void MapTrainer::setName(const QString& name) { - name = n; + m_name = name; } -void MapTrainer::setTrainerClass(const int t) throw(BoundsException) +void MapTrainer::setTrainerClass(const int trainerClass) throw(BoundsException) { - if (pokemod->getTrainerIndex(t) == -1) - throw(BoundsException(className, "trainerClass")); - trainerClass = t; + if (pokemod()->trainerIndex(trainerClass) == INT_MAX) + throw(BoundsException(className(), "trainerClass")); + m_trainerClass = trainerClass; } void MapTrainer::setCoordinate(const int x, const int y) { - coordinate.set(x, y); -} - -void MapTrainer::setCoordinateX(const int x) -{ - coordinate.setX(x); -} - -void MapTrainer::setCoordinateY(const int y) -{ - coordinate.setY(y); + m_coordinate.set(x, y); } -void MapTrainer::setSight(const int s) +void MapTrainer::setSight(const int sight) { - sight = s; + m_sight = sight; } -void MapTrainer::setDirection(const int d) throw(BoundsException) +void MapTrainer::setDirection(const int direction) throw(BoundsException) { - if (Pokemod::D_End_None <= d) - throw(BoundsException(className, "direction")); - direction = d; + if (Pokemod::D_End_None <= direction) + throw(BoundsException(className(), "direction")); + m_direction = direction; } -void MapTrainer::setNumFight(const int n) throw(BoundsException) +void MapTrainer::setNumFight(const int numFight) throw(BoundsException) { - if (!n || (pokemod->getRules()->getMaxFight() < n)) - throw(BoundsException(className, "numFight")); - numFight = n; + if (!numFight || (pokemod()->rules()->maxFight() < numFight)) + throw(BoundsException(className(), "numFight")); + m_numFight = numFight; } -void MapTrainer::setAppearFlag(const int f, const int s) +void MapTrainer::setAppearFlag(const int flag, const int status) { - appearFlag.set(f, s); + m_appearFlag.set(flag, status); } -void MapTrainer::setAppearFlagFlag(const int f) +void MapTrainer::setDialog(const int dialog) throw(BoundsException) { - appearFlag.setFlag(f); + if (pokemod()->dialogIndex(dialog) == INT_MAX) + throw(BoundsException(className(), "dialog")); + m_dialog = dialog; } -void MapTrainer::setAppearFlagStatus(const int s) +void MapTrainer::setLeadTeamMember(const int leadMember) throw(BoundsException) { - appearFlag.setStatus(s); + if (teamMemberCount() <= leadMember) + throw(BoundsException(className(), "leadTeamMember")); + m_leadTeamMember = leadMember; } -void MapTrainer::setDialog(const int d) throw(BoundsException) +QString MapTrainer::name() const { - if (pokemod->getDialogIndex(d) == -1) - throw(BoundsException(className, "dialog")); - dialog = d; + return m_name; } -void MapTrainer::setLeadTeamMember(const int l) throw(BoundsException) +int MapTrainer::trainerClass() const { - if (getTeamMemberCount() <= l) - throw(BoundsException(className, "leadTeamMember")); - leadTeamMember = l; + return m_trainerClass; } -QString MapTrainer::getName() const +Point MapTrainer::coordinate() const { - return name; + return m_coordinate; } -int MapTrainer::getTrainerClass() const +int MapTrainer::sight() const { - return trainerClass; + return m_sight; } -Point MapTrainer::getCoordinate() const +int MapTrainer::direction() const { - return coordinate; + return m_direction; } -int MapTrainer::getSight() const +int MapTrainer::numFight() const { - return sight; + return m_numFight; } -int MapTrainer::getDirection() const +Flag MapTrainer::appearFlag() const { - return direction; + return m_appearFlag; } -int MapTrainer::getNumFight() const +int MapTrainer::dialog() const { - return numFight; + return m_dialog; } -Flag MapTrainer::getAppearFlag() const +int MapTrainer::leadTeamMember() const { - return appearFlag; + return m_leadTeamMember; } -int MapTrainer::getDialog() const +const MapTrainerTeamMember* MapTrainer::teamMember(const int index) const throw(IndexException) { - return dialog; + if (teamMemberCount() <= index) + throw(IndexException(className())); + return m_teamMembers.at(index); } -int MapTrainer::getLeadTeamMember() const +MapTrainerTeamMember* MapTrainer::teamMember(const int index) throw(IndexException) { - return leadTeamMember; + if (teamMemberCount() <= index) + throw(IndexException(className())); + return m_teamMembers[index]; } -const MapTrainerTeamMember* MapTrainer::getTeamMember(const int i) const throw(IndexException) +const MapTrainerTeamMember* MapTrainer::teamMemberById(const int id) const throw(IndexException) { - if (getTeamMemberCount() <= i) - throw(IndexException(className)); - return teamMembers.at(i); + return teamMember(teamMemberIndex(id)); } -MapTrainerTeamMember* MapTrainer::getTeamMember(const int i) throw(IndexException) +MapTrainerTeamMember* MapTrainer::teamMemberById(const int id) throw(IndexException) { - if (getTeamMemberCount() <= i) - throw(IndexException(className)); - return teamMembers[i]; + return teamMember(teamMemberIndex(id)); } -const MapTrainerTeamMember* MapTrainer::getTeamMemberByID(const int i) const throw(IndexException) +int MapTrainer::teamMemberIndex(const int id) const { - return getTeamMember(getTeamMemberIndex(i)); + for (int i = 0; i < teamMemberCount(); ++i) + { + if (m_teamMembers[i]->id() == id) + return i; + } + return INT_MAX; } -MapTrainerTeamMember* MapTrainer::getTeamMemberByID(const int i) throw(IndexException) +int MapTrainer::teamMemberCount() const { - return getTeamMember(getTeamMemberIndex(i)); + return m_teamMembers.size(); } -int MapTrainer::getTeamMemberIndex(const int _id) const +MapTrainerTeamMember* MapTrainer::newTeamMember() { - for (int i = 0; i < getTeamMemberCount(); ++i) - { - if (teamMembers[i]->getId() == _id) - return i; - } - return -1; + m_teamMembers.append(new MapTrainerTeamMember(pokemod(), newTeamMemberId())); + return m_teamMembers[teamMemberCount() - 1]; } -int MapTrainer::getTeamMemberCount() const +MapTrainerTeamMember* MapTrainer::newTeamMember(const QString& fileName) { - return teamMembers.size(); + m_teamMembers.append(new MapTrainerTeamMember(pokemod(), fileName, newTeamMemberId())); + return m_teamMembers[teamMemberCount() - 1]; } -MapTrainerTeamMember* MapTrainer::newTeamMember() +MapTrainerTeamMember* MapTrainer::newTeamMember(const MapTrainerTeamMember& teamMember) { - teamMembers.append(new MapTrainerTeamMember(pokemod, getNewId())); - return teamMembers[getTeamMemberCount() - 1]; + m_teamMembers.append(new MapTrainerTeamMember(pokemod(), teamMember, newTeamMemberId())); + return m_teamMembers[teamMemberCount() - 1]; } -MapTrainerTeamMember* MapTrainer::newTeamMember(const QString& fname) +void MapTrainer::deleteTeamMember(const int index) throw(IndexException) { - teamMembers.append(new MapTrainerTeamMember(pokemod, fname, getNewId())); - return teamMembers[getTeamMemberCount() - 1]; + if (teamMemberCount() <= index) + throw(IndexException(className())); + delete m_teamMembers[index]; + m_teamMembers.removeAt(index); } -MapTrainerTeamMember* MapTrainer::newTeamMember(const MapTrainerTeamMember& p) +void MapTrainer::deleteTeamMemberById(const int id) throw(IndexException) { - teamMembers.append(new MapTrainerTeamMember(pokemod, p, getNewId())); - return teamMembers[getTeamMemberCount() - 1]; + deleteTeamMember(teamMemberIndex(id)); } -void MapTrainer::deleteTeamMember(const int i) throw(IndexException) +int MapTrainer::newTeamMemberId() const { - if (getTeamMemberCount() <= i) - throw(IndexException(className)); - delete teamMembers[i]; - teamMembers.removeAt(i); + int i = 0; + while ((i < teamMemberCount()) && (teamMemberIndex(i) != INT_MAX)) + ++i; + return i; } MapTrainer& MapTrainer::operator=(const MapTrainer& rhs) { if (this == &rhs) return *this; - name = rhs.name; - trainerClass = rhs.trainerClass; - coordinate = rhs.coordinate; - sight = rhs.sight; - direction = rhs.direction; - numFight = rhs.numFight; - appearFlag = rhs.appearFlag; - dialog = rhs.dialog; - leadTeamMember = rhs.leadTeamMember; - teamMembers.clear(); - for (int i = 0; i < rhs.getTeamMemberCount(); ++i) - teamMembers.append(new MapTrainerTeamMember(pokemod, *rhs.getTeamMember(i), rhs.getTeamMember(i)->getId())); + m_name = rhs.m_name; + m_trainerClass = rhs.m_trainerClass; + m_coordinate = rhs.m_coordinate; + m_sight = rhs.m_sight; + m_direction = rhs.m_direction; + m_numFight = rhs.m_numFight; + m_appearFlag = rhs.m_appearFlag; + m_dialog = rhs.m_dialog; + m_leadTeamMember = rhs.m_leadTeamMember; + m_teamMembers.clear(); + foreach (MapTrainerTeamMember* teamMember, rhs.m_teamMembers) + m_teamMembers.append(new MapTrainerTeamMember(pokemod(), *teamMember, teamMember->id())); return *this; } diff --git a/pokemod/MapTrainer.h b/pokemod/MapTrainer.h index f1c02578..bde2631b 100644 --- a/pokemod/MapTrainer.h +++ b/pokemod/MapTrainer.h @@ -1,102 +1,98 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapEffect.h -// Purpose: Define a trainer on a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 22:58:17 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> +// General includes #include <Exception.h> #include <Flag.h> #include <Point.h> +// Pokemod includes #include "Object.h" +// Forward declarations class MapTrainerTeamMember; class Pokemod; class MapTrainer : public Object { public: - MapTrainer(const Pokemod* par, const int _id); - MapTrainer(const Pokemod* par, const MapTrainer& t, const int _id); - MapTrainer(const Pokemod* par, const QString& fname, const int _id = -1); + MapTrainer(const Pokemod* pokemod, const int id); + MapTrainer(const Pokemod* pokemod, const MapTrainer& trainer, const int id); + MapTrainer(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~MapTrainer(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& map) const throw(Exception); - void setName(const QString& n); - void setTrainerClass(const int t) throw(BoundsException); + void setName(const QString& name); + void setTrainerClass(const int trainerClass) throw(BoundsException); void setCoordinate(const int x, const int y); - void setCoordinateX(const int x); - void setCoordinateY(const int y); - void setSight(const int s); - void setDirection(const int d) throw(BoundsException); - void setNumFight(const int n) throw(BoundsException); - void setAppearFlag(const int f, const int s); - void setAppearFlagFlag(const int f); - void setAppearFlagStatus(const int s); - void setDialog(const int d) throw(BoundsException); - void setLeadTeamMember(const int l) throw(BoundsException); + void setSight(const int sight); + void setDirection(const int direction) throw(BoundsException); + void setNumFight(const int numFight) throw(BoundsException); + void setAppearFlag(const int flag, const int status); + void setDialog(const int dialog) throw(BoundsException); + void setLeadTeamMember(const int leadMember) throw(BoundsException); - QString getName() const; - int getTrainerClass() const; - Point getCoordinate() const; - int getSight() const; - int getDirection() const; - int getNumFight() const; - Flag getAppearFlag() const; - int getDialog() const; - int getLeadTeamMember() const; + QString name() const; + int trainerClass() const; + Point coordinate() const; + int sight() const; + int direction() const; + int numFight() const; + Flag appearFlag() const; + int dialog() const; + int leadTeamMember() const; - const MapTrainerTeamMember* getTeamMember(const int i) const throw(IndexException); - MapTrainerTeamMember* getTeamMember(const int i) throw(IndexException); - const MapTrainerTeamMember* getTeamMemberByID(const int i) const throw(IndexException); - MapTrainerTeamMember* getTeamMemberByID(const int i) throw(IndexException); - int getTeamMemberIndex(const int _id) const; - int getTeamMemberCount() const; + const MapTrainerTeamMember* teamMember(const int index) const throw(IndexException); + MapTrainerTeamMember* teamMember(const int index) throw(IndexException); + const MapTrainerTeamMember* teamMemberById(const int id) const throw(IndexException); + MapTrainerTeamMember* teamMemberById(const int id) throw(IndexException); + int teamMemberIndex(const int id) const; + int teamMemberCount() const; MapTrainerTeamMember* newTeamMember(); - MapTrainerTeamMember* newTeamMember(const QString& fname); - MapTrainerTeamMember* newTeamMember(const MapTrainerTeamMember& t); - void deleteTeamMember(const int i) throw(IndexException); + MapTrainerTeamMember* newTeamMember(const QString& fileName); + MapTrainerTeamMember* newTeamMember(const MapTrainerTeamMember& teamMember); + void deleteTeamMember(const int index) throw(IndexException); + void deleteTeamMemberById(const int id) throw(IndexException); MapTrainer& operator=(const MapTrainer& rhs); private: bool validate() const; - int getNewId() const; + int newTeamMemberId() const; - QString name; - int trainerClass; - Point coordinate; - int sight; - int direction; - int numFight; - Flag appearFlag; - int dialog; - int leadTeamMember; + QString m_name; + int m_trainerClass; + Point m_coordinate; + int m_sight; + int m_direction; + int m_numFight; + Flag m_appearFlag; + int m_dialog; + int m_leadTeamMember; - QList<MapTrainerTeamMember*> teamMembers; + QList<MapTrainerTeamMember*> m_teamMembers; }; #endif diff --git a/pokemod/MapTrainerTeamMember.cpp b/pokemod/MapTrainerTeamMember.cpp index 1a14abf2..c733ada0 100644 --- a/pokemod/MapTrainerTeamMember.cpp +++ b/pokemod/MapTrainerTeamMember.cpp @@ -1,213 +1,192 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapTrainerTeamMember.cpp -// Purpose: Define a Pokémon on a trainer's team -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 19:20:21 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - -#include <QListIterator> +/* + * 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/>. + */ + +// Qt includes +#include <QMutableListIterator> #include <QString> +// Pokemod includes #include "Pokemod.h" #include "Item.h" #include "Species.h" + +// Header include #include "MapTrainerTeamMember.h" -MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* par, const int _id) : - Object("MapTrainerTeamMember", par, _id), - species(-1), - level(-1), - nature(-1) +MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* pokemod, const int id) : + Object("MapTrainerTeamMember", pokemod, id), + m_species(INT_MAX), + m_level(INT_MAX), + m_nature(INT_MAX) { } -MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* par, const MapTrainerTeamMember& t, const int _id) : - Object("MapTrainerTeamMember", par, _id) +MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* pokemod, const MapTrainerTeamMember& teamMember, const int id) : + Object("MapTrainerTeamMember", pokemod, id) { - *this = t; + *this = teamMember; } -MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* par, const QString& fname, const int _id) : - Object("MapTrainerTeamMember", par, _id) +MapTrainerTeamMember::MapTrainerTeamMember(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapTrainerTeamMember", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MapTrainerTeamMember::validate() const { bool valid = true; - pokemod->validationMsg(QString("---------Team Member with id %1---").arg(id), Pokemod::V_Msg); - if (pokemod->getSpeciesIndex(species) == -1) + pokemod()->validationMsg(QString("---------Team Member with id %1---").arg(id()), Pokemod::V_Msg); + if (pokemod()->speciesIndex(m_species) == INT_MAX) { - pokemod->validationMsg("Invalid species"); + pokemod()->validationMsg("Invalid species"); valid = false; } - if (pokemod->getRules()->getMaxLevel() <= level) + if (pokemod()->rules()->maxLevel() <= m_level) { - pokemod->validationMsg("Invalid level"); + pokemod()->validationMsg("Invalid level"); valid = false; } - if (items.size() <= pokemod->getRules()->getHoldItems()) + if (m_items.size() <= pokemod()->rules()->holdItems()) { - QMap<int, int> idChecker; - for (QListIterator<int> i(items); i.hasNext(); i.next()) - { - if (pokemod->getItemIndex(i.peekNext()) == -1) - { - pokemod->validationMsg("Invalid item"); - valid = false; - } - ++idChecker[i.peekNext()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + QMap<int, bool> itemChecker; + foreach (int item, m_items) { - if (1 < i.value()) + if (pokemod()->itemIndex(item) == INT_MAX) { - pokemod->validationMsg(QString("There are %1 items with id %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid item"); valid = false; } + if (itemChecker[item]) + pokemod()->validationMsg(QString("Duplicate of item %1").arg(item)); + itemChecker[item] = true; } } else { - pokemod->validationMsg("Too many held items"); + pokemod()->validationMsg("Too many held items"); valid = false; } - if (pokemod->getRules()->getNatureAllowed()) + if (pokemod()->rules()->natureAllowed()) { - if (pokemod->getNatureIndex(nature) == -1) + if (pokemod()->natureIndex(m_nature) == INT_MAX) { - pokemod->validationMsg("Invalid nature"); + pokemod()->validationMsg("Invalid nature"); valid = false; } } return valid; } -void MapTrainerTeamMember::load(const QString& fname, const int _id) throw(Exception) +void MapTrainerTeamMember::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - items.clear(); - ini.getValue("species", species); - ini.getValue("level", level); - ini.getValue("nature", nature); + m_items.clear(); + ini.getValue("species", m_species); + ini.getValue("level", m_level); + ini.getValue("nature", m_nature); ini.getValue("numItems", i, 0); for (int k = 0; k < i; ++k) { ini.getValue(QString("item-%1").arg(k), j); - if (k != -1) - items.append(j); + if (!m_items.contains(j)) + m_items.append(j); } } void MapTrainerTeamMember::save(const QString& map, const QString& trainer) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("species", species); - ini.addField("level", level); - ini.addField("nature", nature); - ini.addField("numItems", items.size()); - for (int i = 0; i < items.size(); ++i) - ini.addField(QString("item-%1").arg(i), items[i]); - ini.save(QString("%1/map/%2/trainer/%3/team/%4.pini").arg(pokemod->getPath()).arg(map).arg(trainer).arg(id)); + ini.addField("id", id()); + ini.addField("species", m_species); + ini.addField("level", m_level); + ini.addField("nature", m_nature); + ini.addField("numItems", m_items.size()); + for (int i = 0; i < m_items.size(); ++i) + ini.addField(QString("item-%1").arg(i), m_items[i]); + ini.save(QString("%1/map/%2/trainer/%3/team/%4.pini").arg(pokemod()->path()).arg(map).arg(trainer).arg(id())); } -void MapTrainerTeamMember::setSpecies(const int s) throw(BoundsException) +void MapTrainerTeamMember::setSpecies(const int species) throw(BoundsException) { - if (pokemod->getSpeciesIndex(s) == -1) - throw(BoundsException(className, "species")); - species = s; + if (pokemod()->speciesIndex(species) == INT_MAX) + throw(BoundsException(className(), "species")); + m_species = species; } -void MapTrainerTeamMember::setLevel(const int l) throw(BoundsException) +void MapTrainerTeamMember::setLevel(const int level) throw(BoundsException) { - if (pokemod->getRules()->getMaxLevel() < l) - throw(BoundsException(className, "level")); - level = l; + if (pokemod()->rules()->maxLevel() < level) + throw(BoundsException(className(), "level")); + m_level = level; } -void MapTrainerTeamMember::setItem(const int itm, const bool it) throw(Exception) +void MapTrainerTeamMember::setItem(const int item, const bool state) throw(BoundsException) { - if (pokemod->getItemIndex(itm) == -1) - throw(BoundsException(className, "item")); - for (QMutableListIterator<int> i(items); i.hasNext(); ) + if (pokemod()->itemIndex(item) == INT_MAX) + throw(BoundsException(className(), "item")); + if (state) { - if (i.next() == itm) - { - if (it) - throw(Exception(className, "item already used")); - else - i.remove(); - } + if (!m_items.contains(item)) + m_items.append(item); } - if (!it) - throw(Exception(className, "item wasn\'t being used anyway")); - if (pokemod->getRules()->getHoldItems() <= items.size()) - throw(Exception(className, "too many items")); - items.append(itm); + else + m_items.removeAll(item); } -void MapTrainerTeamMember::setNature(const int n) throw(BoundsException) +void MapTrainerTeamMember::setNature(const int nature) throw(BoundsException) { - if (!pokemod->getRules()->getNatureAllowed() || (pokemod->getNatureIndex(n) == -1)) - throw(BoundsException(className, "nature")); - nature = n; + if (!pokemod()->rules()->natureAllowed() || (pokemod()->natureIndex(nature) == INT_MAX)) + throw(BoundsException(className(), "nature")); + m_nature = nature; } -int MapTrainerTeamMember::getSpecies() const +int MapTrainerTeamMember::species() const { - return species; + return m_species; } -int MapTrainerTeamMember::getLevel() const +int MapTrainerTeamMember::level() const { - return level; + return m_level; } -int MapTrainerTeamMember::getNature() const +int MapTrainerTeamMember::nature() const { - return nature; + return m_nature; } -bool MapTrainerTeamMember::getItem(const int itm) const +bool MapTrainerTeamMember::item(const int item) const { - for (QListIterator<int> i(items); i.hasNext(); ) - { - if (i.next() == itm) - return true; - } - return false; + return m_items.contains(item); } MapTrainerTeamMember& MapTrainerTeamMember::operator=(const MapTrainerTeamMember& rhs) { if (this == &rhs) return *this; - species = rhs.species; - level = rhs.level; - nature = rhs.nature; - items = rhs.items; + m_species = rhs.m_species; + m_level = rhs.m_level; + m_nature = rhs.m_nature; + m_items = rhs.m_items; return *this; } diff --git a/pokemod/MapTrainerTeamMember.h b/pokemod/MapTrainerTeamMember.h index 1f28a638..a65c1f2f 100644 --- a/pokemod/MapTrainerTeamMember.h +++ b/pokemod/MapTrainerTeamMember.h @@ -1,64 +1,63 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapTrainerTeamMember.h -// Purpose: Define a Pokémon on a trainer's team -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 19:20:21 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class MapTrainerTeamMember : public Object { public: - MapTrainerTeamMember(const Pokemod* par, const int _id); - MapTrainerTeamMember(const Pokemod* par, const MapTrainerTeamMember& t, const int _id); - MapTrainerTeamMember(const Pokemod* par, const QString& fname, const int _id = -1); + MapTrainerTeamMember(const Pokemod* pokemod, const int id); + MapTrainerTeamMember(const Pokemod* pokemod, const MapTrainerTeamMember& teamMember, const int id); + MapTrainerTeamMember(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& map, const QString& trainer) const throw(Exception); - void setSpecies(const int s) throw(BoundsException); - void setLevel(const int l) throw(BoundsException); - void setNature(const int n) throw(BoundsException); - void setItem(const int itm, const bool it) throw(Exception); + void setSpecies(const int species) throw(BoundsException); + void setLevel(const int level) throw(BoundsException); + void setNature(const int nature) throw(BoundsException); + void setItem(const int item, const bool state) throw(BoundsException); - int getSpecies() const; - int getLevel() const; - int getNature() const; - bool getItem(const int itm) const; + int species() const; + int level() const; + int nature() const; + bool item(const int item) const; MapTrainerTeamMember& operator=(const MapTrainerTeamMember& p); private: bool validate() const; - int species; - int level; - int nature; - QList<int> items; + int m_species; + int m_level; + int m_nature; + QList<int> m_items; }; #endif diff --git a/pokemod/MapWarp.cpp b/pokemod/MapWarp.cpp index 35d56de7..050b02e9 100644 --- a/pokemod/MapWarp.cpp +++ b/pokemod/MapWarp.cpp @@ -1,338 +1,316 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapWarp.cpp -// Purpose: Define a warp for a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 20:46:23 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Pokemod includes #include "Pokemod.h" #include "Dialog.h" #include "Map.h" + +// Header include #include "MapWarp.h" const QStringList MapWarp::TypeStr = QStringList() << "Door/Stair" << "Warp Pad" << "Hole" << "Boundary"; -MapWarp::MapWarp(const Pokemod* par, const int _id) : - Object("MapWarp", par, _id), - name(""), - coordinate(0, 0), - directionOut(-1), - warpType(-1), - isBiking(Flag::Ignore), - isFlash(Flag::Ignore), - isFoggy(Flag::Ignore), - toMap(-1), - toWarp(-1), - workingFlag(0, 0), - dialog(-1) +MapWarp::MapWarp(const Pokemod* pokemod, const int id) : + Object("MapWarp", pokemod, id), + m_name(""), + m_coordinate(0, 0), + m_directionOut(INT_MAX), + m_warpType(INT_MAX), + m_isBiking(Flag::Ignore), + m_isFlash(Flag::Ignore), + m_isFoggy(Flag::Ignore), + m_toMap(INT_MAX), + m_toWarp(INT_MAX), + m_workingFlag(0, 0), + m_dialog(INT_MAX) { for (int i = 0; i < Pokemod::D_End; ++i) - from[i] = false; + m_from[i] = false; } -MapWarp::MapWarp(const Pokemod* par, const MapWarp& w, const int _id) : - Object("MapWarp", par, _id) +MapWarp::MapWarp(const Pokemod* pokemod, const MapWarp& warp, const int id) : + Object("MapWarp", pokemod, id) { - *this = w; + *this = warp; } -MapWarp::MapWarp(const Pokemod* par, const QString& fname, const int _id) : - Object("MapWarp", par, _id) +MapWarp::MapWarp(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapWarp", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MapWarp::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Warp \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("------Warp \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (!from[Pokemod::D_Up] && !from[Pokemod::D_Down] && !from[Pokemod::D_Left] && !from[Pokemod::D_Right]) + if (!m_from[Pokemod::D_Up] && !m_from[Pokemod::D_Down] && !m_from[Pokemod::D_Left] && !m_from[Pokemod::D_Right]) { - pokemod->validationMsg("No access from any direction"); + pokemod()->validationMsg("No access from any direction"); valid = false; } - if (Pokemod::D_End_None <= directionOut) + if (Pokemod::D_End_None <= m_directionOut) { - pokemod->validationMsg("Invalid direction out"); + pokemod()->validationMsg("Invalid direction out"); valid = false; } - if (End <= warpType) + if (End <= m_warpType) { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Invalid type"); valid = false; } - if (pokemod->getMapIndex(toMap) != -1) + if (pokemod()->mapIndex(m_toMap) != INT_MAX) { - if (pokemod->getMapByID(toMap)->getWarpIndex(toWarp) == -1) + if (pokemod()->mapById(m_toMap)->warpIndex(m_toWarp) == INT_MAX) { - pokemod->validationMsg("Invalid destnation warp"); + pokemod()->validationMsg("Invalid destination warp"); valid = false; } } else { - pokemod->validationMsg("Invalid destination map"); + pokemod()->validationMsg("Invalid destination map"); valid = false; } - if (pokemod->getDialogIndex(dialog) == -1) + if (pokemod()->dialogIndex(m_dialog) == INT_MAX) { - pokemod->validationMsg("Invalid dialog"); + pokemod()->validationMsg("Invalid dialog"); valid = false; } return valid; } -void MapWarp::load(const QString& fname, const int _id) throw(Exception) +void MapWarp::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); ini.getValue("coordinate-x", i, 0); ini.getValue("coordinate-y", j, 0); - coordinate.set(i, j); - ini.getValue("from-up", from[Pokemod::D_Up], false); - ini.getValue("from-down", from[Pokemod::D_Down], false); - ini.getValue("from-left", from[Pokemod::D_Left], false); - ini.getValue("from-right", from[Pokemod::D_Right], false); - ini.getValue("directionOut", directionOut); - ini.getValue("warpType", warpType); - ini.getValue("isBiking", isBiking, false); - ini.getValue("isFlash", isFlash, false); - ini.getValue("isFoggy", isFoggy, false); - ini.getValue("toMap", toMap); - ini.getValue("toWarp", toWarp); + m_coordinate.set(i, j); + ini.getValue("from-up", m_from[Pokemod::D_Up], false); + ini.getValue("from-down", m_from[Pokemod::D_Down], false); + ini.getValue("from-left", m_from[Pokemod::D_Left], false); + ini.getValue("from-right", m_from[Pokemod::D_Right], false); + ini.getValue("directionOut", m_directionOut); + ini.getValue("warpType", m_warpType); + ini.getValue("isBiking", m_isBiking, false); + ini.getValue("isFlash", m_isFlash, false); + ini.getValue("isFoggy", m_isFoggy, false); + ini.getValue("toMap", m_toMap); + ini.getValue("toWarp", m_toWarp); ini.getValue("workingFlag-f", i, 0); ini.getValue("workingFlag-s", j, 0); - workingFlag.set(i, j); - ini.getValue("dialog", dialog); + m_workingFlag.set(i, j); + ini.getValue("dialog", m_dialog); } void MapWarp::save(const QString& map) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("coordinate-x", coordinate.getX()); - ini.addField("coordinate-y", coordinate.getY()); - ini.addField("from-up", from[Pokemod::D_Up]); - ini.addField("from-down", from[Pokemod::D_Down]); - ini.addField("from-left", from[Pokemod::D_Left]); - ini.addField("from-right", from[Pokemod::D_Right]); - ini.addField("directionOut", directionOut); - ini.addField("warpType", warpType); - ini.addField("isBiking", isBiking); - ini.addField("isFlash", isFlash); - ini.addField("isFoggy", isFoggy); - ini.addField("toMap", toMap); - ini.addField("toWarp", toWarp); - ini.addField("workingFlag-f", workingFlag.getFlag()); - ini.addField("workingFlag-s", workingFlag.getStatus()); - ini.addField("dialog", dialog); - ini.save(QString("%1/map/%2/warp/%3.pini").arg(pokemod->getPath()).arg(map).arg(name)); -} - -void MapWarp::setName(const QString& n) -{ - name = n; + ini.addField("id", id()); + ini.addField("coordinate-x", m_coordinate.x()); + ini.addField("coordinate-y", m_coordinate.y()); + ini.addField("from-up", m_from[Pokemod::D_Up]); + ini.addField("from-down", m_from[Pokemod::D_Down]); + ini.addField("from-left", m_from[Pokemod::D_Left]); + ini.addField("from-right", m_from[Pokemod::D_Right]); + ini.addField("directionOut", m_directionOut); + ini.addField("warpType", m_warpType); + ini.addField("isBiking", m_isBiking); + ini.addField("isFlash", m_isFlash); + ini.addField("isFoggy", m_isFoggy); + ini.addField("toMap", m_toMap); + ini.addField("toWarp", m_toWarp); + ini.addField("workingFlag-f", m_workingFlag.flag()); + ini.addField("workingFlag-s", m_workingFlag.status()); + ini.addField("dialog", m_dialog); + ini.save(QString("%1/map/%2/warp/%3.pini").arg(pokemod()->path()).arg(map).arg(m_name)); +} + +void MapWarp::setName(const QString& name) +{ + m_name = name; } void MapWarp::setCoordinate(const int x, const int y) { - coordinate.set(x, y); -} - -void MapWarp::setCoordinateX(const int x) -{ - coordinate.setX(x); + m_coordinate.set(x, y); } -void MapWarp::setCoordinateY(const int y) +void MapWarp::setFrom(const int direction, const bool can) throw(BoundsException) { - coordinate.setY(y); + if (Pokemod::D_End <= direction) + throw(BoundsException(className(), "direction")); + m_from[direction] = can; } -void MapWarp::setFrom(const int d, const bool f) throw(BoundsException) +void MapWarp::setDirectionOut(const int directionOut) throw(BoundsException) { - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - from[d] = f; + if (Pokemod::D_End <= directionOut) + throw(BoundsException(className(), "direction")); + m_directionOut = directionOut; } -void MapWarp::setDirectionOut(const int d) throw(BoundsException) +void MapWarp::setWarpType(const int warpType) throw(BoundsException) { - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - directionOut = d; -} - -void MapWarp::setWarpType(const int w) throw(BoundsException) -{ - if (End <= w) - throw(BoundsException(className, "warpType")); - warpType = w; -} - -void MapWarp::setIsBiking(const int i) throw(BoundsException) -{ - if (Flag::End <= i) - throw(BoundsException(className, "isBiking")); - isBiking = i; -} - -void MapWarp::setIsFlash(const int i) throw(BoundsException) -{ - if (Flag::End <= i) - throw(BoundsException(className, "isFlash")); - isFlash = i; + if (End <= warpType) + throw(BoundsException(className(), "warpType")); + m_warpType = warpType; } -void MapWarp::setIsFoggy(const int i) throw(BoundsException) +void MapWarp::setIsBiking(const int isBiking) throw(BoundsException) { - if (Flag::End <= i) - throw(BoundsException(className, "isFoggy")); - isFoggy = i; + if (Flag::End <= isBiking) + throw(BoundsException(className(), "isBiking")); + m_isBiking = isBiking; } -void MapWarp::setToMap(const int t) throw(BoundsException) +void MapWarp::setIsFlash(const int isFlash) throw(BoundsException) { - if (pokemod->getMapIndex(t) == -1) - throw(BoundsException(className, "toMap")); - toMap = t; - toWarp = -1; + if (Flag::End <= isFlash) + throw(BoundsException(className(), "isFlash")); + m_isFlash = isFlash; } -void MapWarp::setToWarp(const int t) throw(BoundsException) +void MapWarp::setIsFoggy(const int isFoggy) throw(BoundsException) { - if (pokemod->getMapIndex(toMap) == -1) - throw(BoundsException(className, "toMap")); - if (pokemod->getMapByID(toMap)->getWarpIndex(t) == -1) - throw(BoundsException(className, "toWarp")); + if (Flag::End <= isFoggy) + throw(BoundsException(className(), "isFoggy")); + m_isFoggy = isFoggy; } -void MapWarp::setWorkingFlag(const int f, const int s) +void MapWarp::setToMap(const int toMap) throw(BoundsException) { - workingFlag.set(f, s); + if (pokemod()->mapIndex(toMap) == INT_MAX) + throw(BoundsException(className(), "toMap")); + m_toMap = toMap; + m_toWarp = INT_MAX; } -void MapWarp::setWorkingFlagFlag(const int f) +void MapWarp::setToWarp(const int toWarp) throw(BoundsException) { - workingFlag.setFlag(f); + if (pokemod()->mapIndex(m_toMap) == INT_MAX) + throw(BoundsException(className(), "toMap")); + if (pokemod()->mapById(m_toMap)->warpIndex(toWarp) == INT_MAX) + throw(BoundsException(className(), "toWarp")); + m_toWarp = toWarp; } -void MapWarp::setWorkingFlagStatus(const int s) +void MapWarp::setWorkingFlag(const int flag, const int status) { - workingFlag.setStatus(s); + m_workingFlag.set(flag, status); } -void MapWarp::setDialog(const int d) throw(BoundsException) +void MapWarp::setDialog(const int dialog) throw(BoundsException) { - if (pokemod->getDialogIndex(d) == -1) - throw(BoundsException(className, "dialog")); - dialog = d; + if (pokemod()->dialogIndex(dialog) == INT_MAX) + throw(BoundsException(className(), "dialog")); + m_dialog = dialog; } -QString MapWarp::getName() const +QString MapWarp::name() const { - return name; + return m_name; } -Point MapWarp::getCoordinate() const +Point MapWarp::coordinate() const { - return coordinate; + return m_coordinate; } -bool MapWarp::getFrom(const int d) const throw(BoundsException) +bool MapWarp::from(const int direction) const throw(BoundsException) { - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - return from[d]; + if (Pokemod::D_End <= direction) + throw(BoundsException(className(), "direction")); + return m_from[direction]; } -int MapWarp::getDirectionOut() const +int MapWarp::directionOut() const { - return directionOut; + return m_directionOut; } -int MapWarp::getWarpType() const +int MapWarp::warpType() const { - return warpType; + return m_warpType; } -int MapWarp::getIsBiking() const +int MapWarp::isBiking() const { - return isBiking; + return m_isBiking; } -int MapWarp::getIsFlash() const +int MapWarp::isFlash() const { - return isFlash; + return m_isFlash; } -int MapWarp::getIsFoggy() const +int MapWarp::isFoggy() const { - return isFoggy; + return m_isFoggy; } -int MapWarp::getToMap() const +int MapWarp::toMap() const { - return toMap; + return m_toMap; } -int MapWarp::getToWarp() const +int MapWarp::toWarp() const { - return toWarp; + return m_toWarp; } -Flag MapWarp::getWorkingFlag() const +Flag MapWarp::workingFlag() const { - return workingFlag; + return m_workingFlag; } -int MapWarp::getDialog() const +int MapWarp::dialog() const { - return dialog; + return m_dialog; } MapWarp& MapWarp::operator=(const MapWarp& rhs) { if (this == &rhs) return *this; - name = rhs.name; - coordinate = rhs.coordinate; + m_name = rhs.m_name; + m_coordinate = rhs.m_coordinate; for (int i = 0; i < Pokemod::D_End; ++i) - from[i] = rhs.from[i]; - directionOut = rhs.directionOut; - warpType = rhs.warpType; - isBiking = rhs.isBiking; - isFlash = rhs.isFlash; - isFoggy = rhs.isFoggy; - toMap = rhs.toMap; - toWarp = rhs.toWarp; - workingFlag = rhs.workingFlag; - dialog = rhs.dialog; + m_from[i] = rhs.m_from[i]; + m_directionOut = rhs.m_directionOut; + m_warpType = rhs.m_warpType; + m_isBiking = rhs.m_isBiking; + m_isFlash = rhs.m_isFlash; + m_isFoggy = rhs.m_isFoggy; + m_toMap = rhs.m_toMap; + m_toWarp = rhs.m_toWarp; + m_workingFlag = rhs.m_workingFlag; + m_dialog = rhs.m_dialog; return *this; } diff --git a/pokemod/MapWarp.h b/pokemod/MapWarp.h index a89421a1..7ff26184 100644 --- a/pokemod/MapWarp.h +++ b/pokemod/MapWarp.h @@ -1,35 +1,33 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapEffect.h -// Purpose: Define a warp on a map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 19:47:38 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Flag.h> #include <Point.h> +// Pokemod includes #include "Object.h" #include "Pokemod.h" @@ -46,59 +44,55 @@ class MapWarp : public Object }; static const QStringList TypeStr; - MapWarp(const Pokemod* par, const int _id); - MapWarp(const Pokemod* par, const MapWarp& w, const int _id); - MapWarp(const Pokemod* par, const QString& fname, const int _id = -1); + MapWarp(const Pokemod* pokemod, const int id); + MapWarp(const Pokemod* pokemod, const MapWarp& warp, const int id); + MapWarp(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& map) const throw(Exception); - void setName(const QString& n); + void setName(const QString& name); void setCoordinate(const int x, const int y); - void setCoordinateX(const int x); - void setCoordinateY(const int y); - void setFrom(const int d, const bool f) throw(BoundsException); - void setDirectionOut(const int d) throw(BoundsException); - void setWarpType(const int w) throw(BoundsException); - void setIsBiking(const int i) throw(BoundsException); - void setIsFlash(const int i) throw(BoundsException); - void setIsFoggy(const int i) throw(BoundsException); - void setToMap(const int t) throw(BoundsException); - void setToWarp(const int t) throw(BoundsException); - void setWorkingFlag(const int f, const int s); - void setWorkingFlagFlag(const int f); - void setWorkingFlagStatus(const int s); - void setDialog(const int d) throw(BoundsException); + void setFrom(const int direction, const bool can) throw(BoundsException); + void setDirectionOut(const int directionOut) throw(BoundsException); + void setWarpType(const int warpType) throw(BoundsException); + void setIsBiking(const int isBiking) throw(BoundsException); + void setIsFlash(const int isFlash) throw(BoundsException); + void setIsFoggy(const int isFoggy) throw(BoundsException); + void setToMap(const int toMap) throw(BoundsException); + void setToWarp(const int toWarp) throw(BoundsException); + void setWorkingFlag(const int flag, const int status); + void setDialog(const int dialog) throw(BoundsException); - QString getName() const; - Point getCoordinate() const; - bool getFrom(const int d) const throw(BoundsException); - int getDirectionOut() const; - int getWarpType() const; - int getIsBiking() const; - int getIsFlash() const; - int getIsFoggy() const; - int getToMap() const; - int getToWarp() const; - Flag getWorkingFlag() const; - int getDialog() const; + QString name() const; + Point coordinate() const; + bool from(const int d) const throw(BoundsException); + int directionOut() const; + int warpType() const; + int isBiking() const; + int isFlash() const; + int isFoggy() const; + int toMap() const; + int toWarp() const; + Flag workingFlag() const; + int dialog() const; MapWarp& operator=(const MapWarp& rhs); private: bool validate() const; - QString name; - Point coordinate; - bool from[Pokemod::D_End]; - int directionOut; - int warpType; - int isBiking; - int isFlash; - int isFoggy; - int toMap; - int toWarp; - Flag workingFlag; - int dialog; + QString m_name; + Point m_coordinate; + bool m_from[Pokemod::D_End]; + int m_directionOut; + int m_warpType; + int m_isBiking; + int m_isFlash; + int m_isFoggy; + int m_toMap; + int m_toWarp; + Flag m_workingFlag; + int m_dialog; }; #endif diff --git a/pokemod/MapWildList.cpp b/pokemod/MapWildList.cpp index 737f506d..59ccec3f 100644 --- a/pokemod/MapWildList.cpp +++ b/pokemod/MapWildList.cpp @@ -1,351 +1,352 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapWildList.cpp -// Purpose: Define a list of species that can be found on the map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 19:18:23 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> -#include <QMutableListIterator> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "Item.h" #include "ItemEffect.h" #include "MapWildListEncounter.h" + +// Header include #include "MapWildList.h" const QStringList MapWildList::ControlStr = QStringList() << "Grass" << "Surfing" << "Fishing" << "Dive" << "Headbutt" << "Rock Smash"; -MapWildList::MapWildList(const Pokemod* par, const int _id) : - Object("MapWildList", par, _id), - control(-1), - value(-1), - scope(-1) +MapWildList::MapWildList(const Pokemod* pokemod, const int id) : + Object("MapWildList", pokemod, id), + m_control(INT_MAX), + m_value(INT_MAX), + m_scope(INT_MAX) { } -MapWildList::MapWildList(const Pokemod* par, const MapWildList& w, const int _id) : - Object("MapWildList", par, _id) +MapWildList::MapWildList(const Pokemod* pokemod, const MapWildList& wildList, const int id) : + Object("MapWildList", pokemod, id) { - *this = w; + *this = wildList; } -MapWildList::MapWildList(const Pokemod* par, const QString& fname, const int _id) : - Object("MapWildList", par, _id) +MapWildList::MapWildList(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapWildList", pokemod, id) { - load(fname, _id); + load(fileName, id); } MapWildList::~MapWildList() { - for (QListIterator<MapWildListEncounter*> i(encounters); i.hasNext(); ) - delete i.next(); + foreach (MapWildListEncounter* encounter, m_encounters) + delete encounter; } bool MapWildList::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Wild List with id %1---").arg(id), Pokemod::V_Msg); - if (End <= control) + pokemod()->validationMsg(QString("------Wild List with id %1---").arg(id()), Pokemod::V_Msg); + if (End <= m_control) { - pokemod->validationMsg("Invalid control"); + pokemod()->validationMsg("Invalid control"); valid = false; } - else if (control == Fishing) + else if (m_control == Fishing) { bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Fish) && (e->getVal2() == value)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == m_value)); } } if (!ok) { - pokemod->validationMsg("Invalid fishing value"); + pokemod()->validationMsg("Invalid fishing value"); valid = false; } } - QMap<int, int> idChecker; - for (QListIterator<int> i(times); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + foreach (int time, m_times) { - if (pokemod->getTimeIndex(i.peekNext()) == -1) + if (pokemod()->timeIndex(time) == INT_MAX) { - pokemod->validationMsg("Invalid time"); + pokemod()->validationMsg("Invalid time"); valid = false; } - ++idChecker[i.peekNext()]; + if (idChecker[time]) + pokemod()->validationMsg(QString("Duplicate of time %1").arg(time)); + idChecker[time] = true; } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 of time %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - if (scope != -1) + idChecker.clear(); + if (m_scope != INT_MAX) { bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Scope) && (e->getVal2() == scope)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == m_scope)); } } if (!ok) { - pokemod->validationMsg("Invalid scope"); + pokemod()->validationMsg("Invalid scope"); valid = false; } } - // TODO: MapWildList Encounter validation + if (encounterCount()) + { + foreach (MapWildListEncounter* encounter, m_encounters) + { + if (!encounter->isValid()) + valid = false; + if (idChecker[encounter->id()]) + pokemod()->validationMsg(QString("Duplicate encounter with id %1").arg(encounter->id())); + idChecker[encounter->id()] = true; + } + } + else + { + pokemod()->validationMsg(QString("No effects")); + valid = false; + } return valid; } -int MapWildList::getNewId() const +void MapWildList::load(const QString& fileName, int id) throw(Exception) { - int i = 0; - for (; (i < getEncounterCount()) && (getEncounterIndex(i) != -1); ++i) - ; - return i; -} - -void MapWildList::load(const QString& fname, const int _id) throw(Exception) -{ - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - times.clear(); - ini.getValue("control", control); - ini.getValue("value", value); + m_times.clear(); + ini.getValue("control", m_control); + ini.getValue("value", m_value); ini.getValue("numTimes", i, 0); for (int k = 0; k < i; ++k) { ini.getValue(QString("time-%1").arg(k), j); - if (k != -1) - times.append(j); + if (m_times.contains(j)) + m_times.append(j); } - ini.getValue("scope", scope); - QStringList path = pokemod->getPath().split('/'); + ini.getValue("scope", m_scope); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - encounters.clear(); + m_encounters.clear(); if (fdir.cd("encounter")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEncounter(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newEncounter(file); } } void MapWildList::save(const QString& map) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("control", control); - ini.addField("value", value); - ini.addField("numTimes", times.size()); - for (int i = 0; i < times.size(); ++i) - ini.addField(QString("time-%1").arg(i), times[i]); - ini.addField("scope", scope); - ini.save(QString("%1/map/%2/wildlist/%3/data.pini").arg(pokemod->getPath()).arg(map).arg(id)); - for (QListIterator<MapWildListEncounter*> i(encounters); i.hasNext(); ) - i.next()->save(map, id); + ini.addField("id", id()); + ini.addField("control", m_control); + ini.addField("value", m_value); + ini.addField("numTimes", m_times.size()); + for (int i = 0; i < m_times.size(); ++i) + ini.addField(QString("time-%1").arg(i), m_times[i]); + ini.addField("scope", m_scope); + ini.save(QString("%1/map/%2/wildlist/%3/data.pini").arg(pokemod()->path()).arg(map).arg(id())); + foreach (MapWildListEncounter* encounter, m_encounters) + encounter->save(map, id()); } -void MapWildList::setControl(const int c) throw(BoundsException) +void MapWildList::setControl(const int control) throw(BoundsException) { - if (End <= c) - throw(BoundsException(className, "control")); - control = c; - value = -1; + if (End <= control) + throw(BoundsException(className(), "control")); + m_control = control; + m_value = INT_MAX; } -void MapWildList::setValue(const int v) throw(Exception) +void MapWildList::setValue(const int value) throw(Exception) { - if (control != Fishing) - throw(UnusedException(className, "value")); + if (m_control != Fishing) + throw(UnusedException(className(), "value")); bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Fish) && (e->getVal2() == value)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Fish) && (effect->value2() == value)); } } if (!ok) - throw(BoundsException(className, "value")); - value = v; + throw(BoundsException(className(), "value")); + m_value = value; } -void MapWildList::setTime(const int ts, const bool t) throw(Exception) +void MapWildList::setTime(const int time, const bool state) throw(BoundsException) { - for (QMutableListIterator<int> i(times); i.hasNext(); ) + if (pokemod()->timeIndex(time) == INT_MAX) + throw(BoundsException(className(), "time")); + if (state) { - if (i.next() == ts) - { - if (t) - throw(Exception(className, "time already used")); - else - i.remove(); - } + if (!m_times.contains(time)) + m_times.append(time); } - if (!t) - throw(Exception(className, "time wasn\'t being used anyway")); - times.append(ts); + else + m_times.removeAll(time); } -void MapWildList::setScope(const int s) throw(BoundsException) +void MapWildList::setScope(const int scope) throw(BoundsException) { - if (s != -1) + if (scope != INT_MAX) { bool ok = false; - for (int i = 0; (i < pokemod->getItemCount()) && !ok; ++i) + for (int i = 0; (i < pokemod()->itemCount()) && !ok; ++i) { - const Item* it = pokemod->getItem(i); - for (int j = 0; (j < it->getEffectCount()) && !ok; ++j) + const Item* item = pokemod()->item(i); + for (int j = 0; (j < item->effectCount()) && !ok; ++j) { - const ItemEffect* e = it->getEffect(j); - ok = ((e->getEffect() == ItemEffect::E_Scope) && (e->getVal2() == s)); + const ItemEffect* effect = item->effect(j); + ok = ((effect->effect() == ItemEffect::E_Scope) && (effect->value2() == scope)); } } if (!ok) - throw(BoundsException(className, "scope")); + throw(BoundsException(className(), "scope")); } - scope = s; + m_scope = scope; } -int MapWildList::getControl() const +int MapWildList::control() const { - return control; + return m_control; } -int MapWildList::getValue() const +int MapWildList::value() const { - return value; + return m_value; } -bool MapWildList::getTime(const int ts) const +bool MapWildList::time(const int time) const { - for (QListIterator<int> i(times); i.hasNext(); ) - { - if (i.next() == ts) - return true; - } - return false; + return m_times.contains(time); } -int MapWildList::getScope() const +int MapWildList::scope() const { - return scope; + return m_scope; } -const MapWildListEncounter* MapWildList::getEncounter(const int i) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounter(const int index) const throw(IndexException) { - if (getEncounterCount() <= i) - throw(IndexException(className)); - return encounters.at(i); + if (encounterCount() <= index) + throw(IndexException(className())); + return m_encounters.at(index); } -MapWildListEncounter* MapWildList::getEncounter(const int i) throw(IndexException) +MapWildListEncounter* MapWildList::encounter(const int index) throw(IndexException) { - if (getEncounterCount() <= i) - throw(IndexException(className)); - return encounters[i]; + if (encounterCount() <= index) + throw(IndexException(className())); + return m_encounters[index]; } -const MapWildListEncounter* MapWildList::getEncounterByID(const int i) const throw(IndexException) +const MapWildListEncounter* MapWildList::encounterById(const int id) const throw(IndexException) { - return getEncounter(getEncounterIndex(i)); + return encounter(encounterIndex(id)); } -MapWildListEncounter* MapWildList::getEncounterByID(const int i) throw(IndexException) +MapWildListEncounter* MapWildList::encounterById(const int id) throw(IndexException) { - return getEncounter(getEncounterIndex(i)); + return encounter(encounterIndex(id)); } -int MapWildList::getEncounterIndex(const int _id) const +int MapWildList::encounterIndex(const int id) const { - for (int i = 0; i < getEncounterCount(); ++i) + for (int i = 0; i < encounterCount(); ++i) { - if (encounters[i]->getId() == _id) + if (m_encounters[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int MapWildList::getEncounterCount() const +int MapWildList::encounterCount() const { - return encounters.size(); + return m_encounters.size(); } MapWildListEncounter* MapWildList::newEncounter() { - encounters.append(new MapWildListEncounter(pokemod, getNewId())); - return encounters[getEncounterCount() - 1]; + m_encounters.append(new MapWildListEncounter(pokemod(), newEncounterId())); + return m_encounters[encounterCount() - 1]; } -MapWildListEncounter* MapWildList::newEncounter(const QString& fname) +MapWildListEncounter* MapWildList::newEncounter(const QString& fileName) { - encounters.append(new MapWildListEncounter(pokemod, fname, getNewId())); - return encounters[getEncounterCount() - 1]; + m_encounters.append(new MapWildListEncounter(pokemod(), fileName, newEncounterId())); + return m_encounters[encounterCount() - 1]; } -MapWildListEncounter* MapWildList::newEncounter(const MapWildListEncounter& p) +MapWildListEncounter* MapWildList::newEncounter(const MapWildListEncounter& encounter) { - encounters.append(new MapWildListEncounter(pokemod, p, getNewId())); - return encounters[getEncounterCount() - 1]; + m_encounters.append(new MapWildListEncounter(pokemod(), encounter, newEncounterId())); + return m_encounters[encounterCount() - 1]; } -void MapWildList::deleteEncounter(const int i) throw(IndexException) +void MapWildList::deleteEncounter(const int index) throw(IndexException) { - if (getEncounterCount() <= i) - throw(IndexException(className)); - delete encounters[i]; - encounters.removeAt(i); + if (encounterCount() <= index) + throw(IndexException(className())); + delete m_encounters[index]; + m_encounters.removeAt(index); +} + +void MapWildList::deleteEncounterById(const int id) throw(IndexException) +{ + deleteEncounter(encounterIndex(id)); +} + +int MapWildList::newEncounterId() const +{ + int i = 0; + while ((i < encounterCount()) && (encounterIndex(i) != INT_MAX)) + ++i; + return i; } MapWildList& MapWildList::operator=(const MapWildList& rhs) { if (this == &rhs) return *this; - control = rhs.control; - value = rhs.value; - times = rhs.times; - scope = rhs.scope; - encounters.clear(); - for (int i = 0; i < rhs.getEncounterCount(); ++i) - encounters.append(new MapWildListEncounter(pokemod, *rhs.getEncounter(i), rhs.getEncounter(i)->getId())); + m_control = rhs.m_control; + m_value = rhs.m_value; + m_times = rhs.m_times; + m_scope = rhs.m_scope; + m_encounters.clear(); + foreach (MapWildListEncounter* encounter, rhs.m_encounters) + m_encounters.append(new MapWildListEncounter(pokemod(), *encounter, encounter->id())); return *this; } diff --git a/pokemod/MapWildList.h b/pokemod/MapWildList.h index 6026f18b..075157b7 100644 --- a/pokemod/MapWildList.h +++ b/pokemod/MapWildList.h @@ -1,36 +1,35 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapWildList.h -// Purpose: Define a list of species that can be found on the map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 19:18:23 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> #include <QStringList> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class MapWildListEncounter; class Pokemod; @@ -49,46 +48,47 @@ class MapWildList : public Object }; static const QStringList ControlStr; - MapWildList(const Pokemod* par, const int _id); - MapWildList(const Pokemod* par, const MapWildList& w, const int _id); - MapWildList(const Pokemod* par, const QString& fname, const int _id = -1); + MapWildList(const Pokemod* pokemod, const int id); + MapWildList(const Pokemod* pokemod, const MapWildList& wildList, const int id); + MapWildList(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~MapWildList(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& map) const throw(Exception); - void setControl(const int c) throw(BoundsException); - void setValue(const int v) throw(Exception); - void setTime(const int ts, const bool t) throw(Exception); - void setScope(const int s) throw(BoundsException); + void setControl(const int control) throw(BoundsException); + void setValue(const int value) throw(Exception); + void setTime(const int time, const bool state) throw(BoundsException); + void setScope(const int scope) throw(BoundsException); - int getControl() const; - int getValue() const; - bool getTime(const int ts) const; - int getScope() const; + int control() const; + int value() const; + bool time(const int time) const; + int scope() const; - const MapWildListEncounter* getEncounter(const int i) const throw(IndexException); - MapWildListEncounter* getEncounter(const int i) throw(IndexException); - const MapWildListEncounter* getEncounterByID(const int i) const throw(IndexException); - MapWildListEncounter* getEncounterByID(const int i) throw(IndexException); - int getEncounterIndex(const int _id) const; - int getEncounterCount() const; + const MapWildListEncounter* encounter(const int index) const throw(IndexException); + MapWildListEncounter* encounter(const int index) throw(IndexException); + const MapWildListEncounter* encounterById(const int id) const throw(IndexException); + MapWildListEncounter* encounterById(const int id) throw(IndexException); + int encounterIndex(const int id) const; + int encounterCount() const; MapWildListEncounter* newEncounter(); - MapWildListEncounter* newEncounter(const QString& fname); - MapWildListEncounter* newEncounter(const MapWildListEncounter& w); - void deleteEncounter(const int i) throw(IndexException); + MapWildListEncounter* newEncounter(const QString& fileName); + MapWildListEncounter* newEncounter(const MapWildListEncounter& encounter); + void deleteEncounter(const int index) throw(IndexException); + void deleteEncounterById(const int id) throw(IndexException); MapWildList& operator=(const MapWildList& rhs); private: bool validate() const; - int getNewId() const; + int newEncounterId() const; - int control; - int value; - QList<int> times; - int scope; + int m_control; + int m_value; + QList<int> m_times; + int m_scope; - QList<MapWildListEncounter*> encounters; + QList<MapWildListEncounter*> m_encounters; }; #endif diff --git a/pokemod/MapWildListEncounter.cpp b/pokemod/MapWildListEncounter.cpp index 9d85403a..3608b409 100644 --- a/pokemod/MapWildListEncounter.cpp +++ b/pokemod/MapWildListEncounter.cpp @@ -1,135 +1,132 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapWildListEncounter.cpp -// Purpose: Define a species that can be found in the wild -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:50:59 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Pokemod includes #include "Pokemod.h" #include "Species.h" + +// Header include #include "MapWildListEncounter.h" -MapWildListEncounter::MapWildListEncounter(const Pokemod* par, const int _id) : - Object("MapWildListEncounter", par, _id), - species(-1), - level(1), - weight(1) +MapWildListEncounter::MapWildListEncounter(const Pokemod* pokemod, const int id) : + Object("MapWildListEncounter", pokemod, id), + m_species(INT_MAX), + m_level(1), + m_weight(1) { } -MapWildListEncounter::MapWildListEncounter(const Pokemod* par, const MapWildListEncounter& p, const int _id) : - Object("MapWildListEncounter", par, _id) +MapWildListEncounter::MapWildListEncounter(const Pokemod* pokemod, const MapWildListEncounter& encounter, const int id) : + Object("MapWildListEncounter", pokemod, id) { - *this = p; + *this = encounter; } -MapWildListEncounter::MapWildListEncounter(const Pokemod* par, const QString& fname, const int _id) : - Object("MapWildListEncounter", par, _id) +MapWildListEncounter::MapWildListEncounter(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MapWildListEncounter", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MapWildListEncounter::validate() const { bool valid = true; - pokemod->validationMsg(QString("---------Encounter with id %1---").arg(id), Pokemod::V_Msg); - if (pokemod->getSpeciesIndex(species) == -1) + pokemod()->validationMsg(QString("---------Encounter with id %1---").arg(id()), Pokemod::V_Msg); + if (pokemod()->speciesIndex(m_species) == INT_MAX) { - pokemod->validationMsg("Invalid species"); + pokemod()->validationMsg("Invalid species"); valid = false; } - if (!level || (pokemod->getRules()->getMaxLevel() <= level)) + if (!m_level || (pokemod()->rules()->maxLevel() <= m_level)) { - pokemod->validationMsg("Invalid level"); + pokemod()->validationMsg("Invalid level"); valid = false; } - if (!weight) + if (!m_weight) { - pokemod->validationMsg("Invalid weighting"); + pokemod()->validationMsg("Invalid weighting"); valid = false; } return valid; } -void MapWildListEncounter::load(const QString& fname, const int _id) throw(Exception) +void MapWildListEncounter::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("species", species); - ini.getValue("level", level, 1); - ini.getValue("weight", weight, 1); + setId(id); + ini.getValue("species", m_species); + ini.getValue("level", m_level, 1); + ini.getValue("weight", m_weight, 1); } void MapWildListEncounter::save(const QString& map, const int listId) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("species", species); - ini.addField("level", level); - ini.addField("weight", weight); - ini.save(QString("%1/map/%2/wildlist/%3/encounter/%4.pini").arg(pokemod->getPath()).arg(map).arg(listId).arg(id)); + ini.addField("id", id()); + ini.addField("species", m_species); + ini.addField("level", m_level); + ini.addField("weight", m_weight); + ini.save(QString("%1/map/%2/wildlist/%3/encounter/%4.pini").arg(pokemod()->path()).arg(map).arg(listId).arg(id())); } -void MapWildListEncounter::setSpecies(const int s) throw(BoundsException) +void MapWildListEncounter::setSpecies(const int species) throw(BoundsException) { - if (pokemod->getSpeciesIndex(s) == -1) - throw(BoundsException(className, "species")); - species = s; + if (pokemod()->speciesIndex(species) == INT_MAX) + throw(BoundsException(className(), "species")); + m_species = species; } -void MapWildListEncounter::setLevel(const int l) throw(BoundsException) +void MapWildListEncounter::setLevel(const int level) throw(BoundsException) { - if (!level || (pokemod->getRules()->getMaxLevel() <= level)) - throw(BoundsException(className, "level")); - level = l; + if (!level || (pokemod()->rules()->maxLevel() <= level)) + throw(BoundsException(className(), "level")); + m_level = level; } -void MapWildListEncounter::setWeight(const int w) throw(BoundsException) +void MapWildListEncounter::setWeight(const int weight) throw(BoundsException) { - if (!w) - throw(BoundsException(className, "weight")); - weight = w; + if (!weight) + throw(BoundsException(className(), "weight")); + m_weight = weight; } -int MapWildListEncounter::getSpecies() const +int MapWildListEncounter::species() const { - return species; + return m_species; } -int MapWildListEncounter::getLevel() const +int MapWildListEncounter::level() const { - return level; + return m_level; } -int MapWildListEncounter::getWeight() const +int MapWildListEncounter::weight() const { - return weight; + return m_weight; } MapWildListEncounter& MapWildListEncounter::operator=(const MapWildListEncounter& rhs) { if (this == &rhs) return *this; - species = rhs.species; - level = rhs.level; - weight = rhs.weight; + m_species = rhs.m_species; + m_level = rhs.m_level; + m_weight = rhs.m_weight; return *this; } diff --git a/pokemod/MapWildListEncounter.h b/pokemod/MapWildListEncounter.h index 5311627d..7f7e4798 100644 --- a/pokemod/MapWildListEncounter.h +++ b/pokemod/MapWildListEncounter.h @@ -1,61 +1,60 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MapWildListEncounter.h -// Purpose: Define a species that can be found in the wild -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:50:59 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class MapWildListEncounter: public Object { public: - MapWildListEncounter(const Pokemod* par, const int _id); - MapWildListEncounter(const Pokemod* par, const MapWildListEncounter& p, const int _id); - MapWildListEncounter(const Pokemod* par, const QString& fname, const int _id = -1); + MapWildListEncounter(const Pokemod* pokemod, const int id); + MapWildListEncounter(const Pokemod* pokemod, const MapWildListEncounter& encounter, const int id); + MapWildListEncounter(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& map, const int listId) const throw(Exception); - void setSpecies(const int s) throw(BoundsException); - void setLevel(const int l) throw(BoundsException); - void setWeight(const int w) throw(BoundsException); + void setSpecies(const int species) throw(BoundsException); + void setLevel(const int level) throw(BoundsException); + void setWeight(const int weight) throw(BoundsException); - int getSpecies() const; - int getLevel() const; - int getWeight() const; + int species() const; + int level() const; + int weight() const; MapWildListEncounter& operator=(const MapWildListEncounter& rhs); private: bool validate() const; - int species; - int level; - int weight; + int m_species; + int m_level; + int m_weight; }; #endif diff --git a/pokemod/Move.cpp b/pokemod/Move.cpp index 6f8ad323..aaf6af7b 100644 --- a/pokemod/Move.cpp +++ b/pokemod/Move.cpp @@ -1,451 +1,437 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Move.cpp -// Purpose: Define a move that can be learned -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sat May 26 2007 22:51:21 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "MoveEffect.h" + +// Header include #include "Move.h" -const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "Both" << "Random"; +const QStringList Move::TargetStr = QStringList() << "Player" << "Enemy" << "All" << "Random"; const QStringList Move::ChoiceStr = QStringList() << "Player" << "Enemy" << "Random"; -Move::Move(const Pokemod* par, const int _id) : - Object("Move", par, _id), - name(""), - accuracy(1, 1), - power(0), - type(-1), - special(false), - powerPoints(0), - target(-1), - targetChoice(-1), - ignoreAccuracy(false), - canFlinch(false), - canRandom(false), - canSnatch(false), - sound(false), - description("") +Move::Move(const Pokemod* pokemod, const int id) : + Object("Move", pokemod, id), + m_name(""), + m_accuracy(1, 1), + m_power(0), + m_type(INT_MAX), + m_special(false), + m_powerPoints(0), + m_target(INT_MAX), + m_targetChoice(INT_MAX), + m_ignoreAccuracy(false), + m_canFlinch(false), + m_canRandom(false), + m_canSnatch(false), + m_sound(false), + m_priority(1), + m_description("") { } -Move::Move(const Pokemod* par, const Move& m, const int _id) : - Object("Move", par, _id) +Move::Move(const Pokemod* pokemod, const Move& move, const int id) : + Object("Move", pokemod, id) { - *this = m; + *this = move; } -Move::Move(const Pokemod* par, const QString& fname, const int _id) : - Object("Move", par, _id) +Move::Move(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Move", pokemod, id) { - load(fname, _id); + load(fileName, id); } Move::~Move() { - for (QListIterator<MoveEffect*> i(effects); i.hasNext(); ) - delete i.next(); + foreach (MoveEffect* effect, m_effects) + delete effect; } bool Move::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Move \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Move \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = ""; } - if (pokemod->getTypeIndex(type) == -1) + if (pokemod()->typeIndex(m_type) == INT_MAX) { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Invalid type"); valid = false; } - if (!powerPoints) + if (!m_powerPoints) { - pokemod->validationMsg("Invalid number of power points"); + pokemod()->validationMsg("Invalid number of power points"); valid = false; } - if (T_End <= target) + if (T_End <= m_target) { - pokemod->validationMsg("Invalid target"); + pokemod()->validationMsg("Invalid target"); valid = false; } - if (!target || (pokemod->getRules()->getMaxFight() << (target == T_Both)) < numTargets) + if (!m_target || (pokemod()->rules()->maxFight() * ((m_target == T_All) ? pokemod()->rules()->maxPlayers() : 1)) < m_numTargets) { - pokemod->validationMsg("Invalid number of targets"); + pokemod()->validationMsg("Invalid number of targets"); valid = false; } - if (C_End <= targetChoice) + if (C_End <= m_targetChoice) { - pokemod->validationMsg("Invalid target choice"); + pokemod()->validationMsg("Invalid target choice"); valid = false; } - if (getEffectCount()) + if (effectCount()) { - QMap<int, int> idChecker; - for (QListIterator<MoveEffect*> i(effects); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + foreach (MoveEffect* effect, m_effects) { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key())); + if (!effect->isValid()) valid = false; - } + if (idChecker[effect->id()]) + pokemod()->validationMsg(QString("Duplicate effect with id %1").arg(effect->id())); + idChecker[effect->id()] = true; } } else { - pokemod->validationMsg("There are no effects"); + pokemod()->validationMsg("There are no effects"); valid = false; } return valid; } -int Move::getNewId() const +void Move::load(const QString& fileName, int id) throw(Exception) { - int i = 0; - for (; (i < getEffectCount()) && (getEffectIndex(i) != -1); ++i) - ; - return i; -} - -void Move::load(const QString& fname, const int _id) throw(Exception) -{ - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); ini.getValue("accuracy-n", i, 1); ini.getValue("accuracy-d", j, 1); - accuracy.set(i, j); - ini.getValue("power", power, 0); - ini.getValue("type", type); - ini.getValue("special", special, false); - ini.getValue("powerPoints", powerPoints, 1); - ini.getValue("target", target); - ini.getValue("numTargets", numTargets, 0); - ini.getValue("targetChoice", targetChoice); - ini.getValue("ignoreAccuracy", ignoreAccuracy, false); - ini.getValue("canFlinch", canFlinch, false); - ini.getValue("canRandom", canRandom, false); - ini.getValue("canSnatch", canSnatch, false); - ini.getValue("sound", sound, false); - ini.getValue("description", description, ""); - QStringList path = pokemod->getPath().split('/'); + m_accuracy.set(i, j); + ini.getValue("power", m_power, 0); + ini.getValue("type", m_type); + ini.getValue("special", m_special, false); + ini.getValue("powerPoints", m_powerPoints, 1); + ini.getValue("target", m_target); + ini.getValue("numTargets", m_numTargets, 0); + ini.getValue("targetChoice", m_targetChoice); + ini.getValue("ignoreAccuracy", m_ignoreAccuracy, false); + ini.getValue("canFlinch", m_canFlinch, false); + ini.getValue("canRandom", m_canRandom, false); + ini.getValue("canSnatch", m_canSnatch, false); + ini.getValue("sound", m_sound, false); + ini.getValue("description", m_description, ""); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - effects.clear(); + m_effects.clear(); if (fdir.cd("effect")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEffect(i.next()); + QStringList files(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); + foreach (QString file, files) + newEffect(file); } } void Move::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("accuracy-n", accuracy.getNum()); - ini.addField("accuracy-d", accuracy.getDenom()); - ini.addField("power", power); - ini.addField("type", type); - ini.addField("special", special); - ini.addField("powerPoints", powerPoints); - ini.addField("target", target); - ini.addField("numTargets", numTargets); - ini.addField("targetChoice", targetChoice); - ini.addField("ignoreAccuracy", ignoreAccuracy); - ini.addField("canFlinch", canFlinch); - ini.addField("canRandom", canRandom); - ini.addField("canSnatch", canSnatch); - ini.addField("sound", sound); - ini.addField("description", description); - ini.save(QString("%1/move/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<MoveEffect*> i(effects); i.hasNext(); ) - i.next()->save(name); -} - -void Move::setName(const QString& n) -{ - name = n; + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("accuracy-n", m_accuracy.numerator()); + ini.addField("accuracy-d", m_accuracy.denominator()); + ini.addField("power", m_power); + ini.addField("type", m_type); + ini.addField("special", m_special); + ini.addField("powerPoints", m_powerPoints); + ini.addField("target", m_target); + ini.addField("numTargets", m_numTargets); + ini.addField("targetChoice", m_targetChoice); + ini.addField("ignoreAccuracy", m_ignoreAccuracy); + ini.addField("canFlinch", m_canFlinch); + ini.addField("canRandom", m_canRandom); + ini.addField("canSnatch", m_canSnatch); + ini.addField("sound", m_sound); + ini.addField("description", m_description); + ini.save(QString("%1/move/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (MoveEffect* effect, m_effects) + effect->save(m_name); +} + +void Move::setName(const QString& name) +{ + m_name = name; } void Move::setAccuracy(const int n, const int d) throw(Exception) { - accuracy.set(n, d); + m_accuracy.set(n, d); } -void Move::setAccuracyNum(const int n) throw(Exception) +void Move::setType(const int type) throw(BoundsException) { - accuracy.setNum(n); + if (pokemod()->typeIndex(type) == INT_MAX) + throw(BoundsException(className(), "type")); + m_type = type; } -void Move::setAccuracyDenom(const int d) throw(Exception) +void Move::setSpecial(const bool special) { - accuracy.setDenom(d); + m_special = special; } -void Move::setType(const int t) throw(BoundsException) +void Move::setPowerPoints(const int powerPoints) throw(BoundsException) { - if (pokemod->getTypeIndex(t) == -1) - throw(BoundsException(className, "type")); - type = t; + if (!powerPoints) + throw(BoundsException(className(), "powerPoints")); + m_powerPoints = powerPoints; } -void Move::setSpecial(const bool s) +void Move::setTarget(const int target) throw(BoundsException) { - special = s; + if (T_End <= target) + throw(BoundsException(className(), "target")); + m_target = target; } -void Move::setPowerPoints(const int p) throw(BoundsException) +void Move::setNumTargets(const int numTargets) throw(BoundsException) { - if (!p) - throw(BoundsException(className, "powerPoints")); - powerPoints = p; + if (!numTargets || ((pokemod()->rules()->maxFight() * ((m_target == T_All) ? pokemod()->rules()->maxPlayers() : 1)) < numTargets)) + throw(BoundsException(className(), "numTargets")); + m_numTargets = numTargets; } -void Move::setTarget(const int t) throw(BoundsException) +void Move::setTargetChoice(const int targetChoice) throw(BoundsException) { - if (T_End <= t) - throw(BoundsException(className, "target")); - target = t; + if (C_End <= targetChoice) + throw(BoundsException(className(), "targetChoice")); + m_targetChoice = targetChoice; } -void Move::setNumTargets(const int n) throw(BoundsException) +void Move::setIgnoreAccuracy(const bool ignoreAccuracy) { - if (!n || ((pokemod->getRules()->getMaxFight() << 1) < n)) - throw(BoundsException(className, "numTargets")); - numTargets = n; + m_ignoreAccuracy = ignoreAccuracy; } -void Move::setTargetChoice(const int t) throw(BoundsException) +void Move::setCanFlinch(const bool canFlinch) { - if (C_End <= t) - throw(BoundsException(className, "targetChoice")); - targetChoice = t; + m_canFlinch = canFlinch; } -void Move::setIgnoreAccuracy(const bool i) +void Move::setCanRandom(const bool canRandom) { - ignoreAccuracy = i; + m_canRandom = canRandom; } -void Move::setCanFlinch(const bool c) +void Move::setCanSnatch(const bool canSnatch) { - canFlinch = c; + m_canSnatch = canSnatch; } -void Move::setCanRandom(const bool c) +void Move::setSound(const bool sound) { - canRandom = c; + m_sound = sound; } -void Move::setCanSnatch(const bool c) +void Move::setDescription(const QString& description) { - canSnatch = c; + m_description = description; } -void Move::setSound(const bool s) +QString Move::name() const { - sound = s; + return m_name; } -void Move::setDescription(const QString& d) +Frac Move::accuracy() const { - description = d; + return m_accuracy; } -QString Move::getName() const +int Move::type() const { - return name; + return m_type; } -Frac Move::getAccuracy() const +bool Move::special() const { - return accuracy; + return m_special; } -int Move::getType() const +int Move::powerPoints() const { - return type; + return m_powerPoints; } -bool Move::getSpecial() const +int Move::target() const { - return special; + return m_target; } -int Move::getPowerPoints() const +int Move::numTargets() const { - return powerPoints; + return m_numTargets; } -int Move::getTarget() const +int Move::targetChoice() const { - return target; + return m_targetChoice; } -int Move::getNumTargets() const +bool Move::ignoreAccuracy() const { - return numTargets; + return m_ignoreAccuracy; } -int Move::getTargetChoice() const +bool Move::canFlinch() const { - return targetChoice; + return m_canFlinch; } -bool Move::getIgnoreAccuracy() const +bool Move::canRandom() const { - return ignoreAccuracy; + return m_canRandom; } -bool Move::getCanFlinch() const +bool Move::canSnatch() const { - return canFlinch; + return m_canSnatch; } -bool Move::getCanRandom() const +bool Move::sound() const { - return canRandom; + return m_sound; } -bool Move::getCanSnatch() const +QString Move::description() const { - return canSnatch; + return m_description; } -bool Move::getSound() const +const MoveEffect* Move::effect(const int index) const throw(IndexException) { - return sound; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects.at(index); } -QString Move::getDescription() const +MoveEffect* Move::effect(const int index) throw(IndexException) { - return description; + if (effectCount() <= index) + throw(IndexException(className())); + return m_effects[index]; } -const MoveEffect* Move::getEffect(const int i) const throw(IndexException) +const MoveEffect* Move::effectById(const int id) const throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects.at(i); + return effect(effectIndex(id)); } -MoveEffect* Move::getEffect(const int i) throw(IndexException) +MoveEffect* Move::effectById(const int id) throw(IndexException) { - if (getEffectCount() <= i) - throw(IndexException(className)); - return effects[i]; + return effect(effectIndex(id)); } -const MoveEffect* Move::getEffectByID(const int i) const throw(IndexException) +int Move::effectIndex(const int id) const { - return getEffect(getEffectIndex(i)); + for (int i = 0; i < effectCount(); ++i) + { + if (m_effects[i]->id() == id) + return i; + } + return INT_MAX; } -MoveEffect* Move::getEffectByID(const int i) throw(IndexException) +int Move::effectCount() const { - return getEffect(getEffectIndex(i)); + return m_effects.size(); } -int Move::getEffectIndex(const int _id) const +MoveEffect* Move::newEffect() { - for (int i = 0; i < getEffectCount(); ++i) - { - if (effects[i]->getId() == _id) - return i; - } - return -1; + m_effects.append(new MoveEffect(pokemod(), newEffectId())); + return m_effects[effectCount() - 1]; } -int Move::getEffectCount() const +MoveEffect* Move::newEffect(const QString& fileName) { - return effects.size(); + m_effects.append(new MoveEffect(pokemod(), fileName, newEffectId())); + return m_effects[effectCount() - 1]; } -MoveEffect* Move::newEffect() +MoveEffect* Move::newEffect(const MoveEffect& effect) { - effects.append(new MoveEffect(pokemod, getNewId())); - return effects[getEffectCount() - 1]; + m_effects.append(new MoveEffect(pokemod(), effect, newEffectId())); + return m_effects[effectCount() - 1]; } -MoveEffect* Move::newEffect(const QString& fname) +void Move::deleteEffect(const int index) throw(IndexException) { - effects.append(new MoveEffect(pokemod, fname, getNewId())); - return effects[getEffectCount() - 1]; + if (effectCount() <= index) + throw(IndexException(className())); + delete m_effects[index]; + m_effects.removeAt(index); } -MoveEffect* Move::newEffect(const MoveEffect& e) +void Move::deleteEffectById(const int id) throw(IndexException) { - effects.append(new MoveEffect(pokemod, e, getNewId())); - return effects[getEffectCount() - 1]; + deleteEffect(effectIndex(id)); } -void Move::deleteEffect(const int i) throw(IndexException) +int Move::newEffectId() const { - if (getEffectCount() <= i) - throw(IndexException(className)); - delete effects[i]; - effects.removeAt(i); + int i = 0; + while ((i < effectCount()) && (effectIndex(i) != INT_MAX)) + ++i; + return i; } Move& Move::operator=(const Move& rhs) { if (this == &rhs) return *this; - name = rhs.name; - accuracy = rhs.accuracy; - power = rhs.power; - type = rhs.type; - special = rhs.special; - powerPoints = rhs.powerPoints; - target = rhs.target; - numTargets = rhs.numTargets; - targetChoice = rhs.targetChoice; - ignoreAccuracy = rhs.ignoreAccuracy; - canFlinch = rhs.canFlinch; - canRandom = rhs.canRandom; - canSnatch = rhs.canSnatch; - sound = rhs.sound; - description = rhs.description; - effects.clear(); - for (int i = 0; i < rhs.getEffectCount(); ++i) - effects.append(new MoveEffect(pokemod, *rhs.getEffect(i), rhs.getEffect(i)->getId())); + m_name = rhs.m_name; + m_accuracy = rhs.m_accuracy; + m_power = rhs.m_power; + m_type = rhs.m_type; + m_special = rhs.m_special; + m_powerPoints = rhs.m_powerPoints; + m_target = rhs.m_target; + m_numTargets = rhs.m_numTargets; + m_targetChoice = rhs.m_targetChoice; + m_ignoreAccuracy = rhs.m_ignoreAccuracy; + m_canFlinch = rhs.m_canFlinch; + m_canRandom = rhs.m_canRandom; + m_canSnatch = rhs.m_canSnatch; + m_sound = rhs.m_sound; + m_description = rhs.m_description; + m_effects.clear(); + foreach (MoveEffect* effect, rhs.m_effects) + m_effects.append(new MoveEffect(pokemod(), *effect, effect->id())); return *this; } diff --git a/pokemod/Move.h b/pokemod/Move.h index 044f1b71..ea93da98 100644 --- a/pokemod/Move.h +++ b/pokemod/Move.h @@ -1,37 +1,36 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Move.h -// Purpose: Define a move that can be learned -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sat May 26 2007 08:57:13 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" +// Forward declarations class MoveEffect; class Pokemod; @@ -42,7 +41,7 @@ class Move : public Object { T_Player = 0, T_Enemy = 1, - T_Both = 2, + T_All = 2, T_Random = 3, T_End = 4 }; @@ -57,79 +56,81 @@ class Move : public Object }; static const QStringList ChoiceStr; - Move(const Pokemod* par, const int _id); - Move(const Pokemod* par, const Move& m, const int _id); - Move(const Pokemod* par, const QString& fname, const int _id = -1); + Move(const Pokemod* pokemod, const int id); + Move(const Pokemod* pokemod, const Move& move, const int id); + Move(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~Move(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setAccuracy(const int n, const int d) throw(Exception); - void setAccuracyNum(const int n) throw(Exception); - void setAccuracyDenom(const int d) throw(Exception); - void setType(const int t) throw(BoundsException); - void setSpecial(const bool s); - void setPowerPoints(const int p) throw(BoundsException); - void setTarget(const int t) throw(BoundsException); - void setNumTargets(const int n) throw(BoundsException); - void setTargetChoice(const int t) throw(BoundsException); - void setIgnoreAccuracy(const bool i); - void setCanFlinch(const bool c); - void setCanRandom(const bool c); - void setCanSnatch(const bool c); - void setSound(const bool s); - void setDescription(const QString& d); + void setName(const QString& name); + void setAccuracy(const int numerator, const int denominator) throw(Exception); + void setType(const int type) throw(BoundsException); + void setSpecial(const bool special); + void setPowerPoints(const int powerPoints) throw(BoundsException); + void setTarget(const int target) throw(BoundsException); + void setNumTargets(const int numTargets) throw(BoundsException); + void setTargetChoice(const int targetChoice) throw(BoundsException); + void setIgnoreAccuracy(const bool ignoreAccuracy); + void setCanFlinch(const bool canFlinch); + void setCanRandom(const bool canRandom); + void setCanSnatch(const bool canSnatch); + void setSound(const bool sound); + void setPriority(const int priority); + void setDescription(const QString& description); - QString getName() const; - Frac getAccuracy() const; - int getType() const; - bool getSpecial() const; - int getPowerPoints() const; - int getTarget() const; - int getNumTargets() const; - int getTargetChoice() const; - bool getIgnoreAccuracy() const; - bool getCanFlinch() const; - bool getCanRandom() const; - bool getCanSnatch() const; - bool getSound() const; - QString getDescription() const; + QString name() const; + Frac accuracy() const; + int type() const; + bool special() const; + int powerPoints() const; + int target() const; + int numTargets() const; + int targetChoice() const; + bool ignoreAccuracy() const; + bool canFlinch() const; + bool canRandom() const; + bool canSnatch() const; + bool sound() const; + int priority() const; + QString description() const; - const MoveEffect* getEffect(const int i) const throw(IndexException); - MoveEffect* getEffect(const int i) throw(IndexException); - const MoveEffect* getEffectByID(const int i) const throw(IndexException); - MoveEffect* getEffectByID(const int i) throw(IndexException); - int getEffectIndex(const int _id) const; - int getEffectCount() const; + const MoveEffect* effect(const int index) const throw(IndexException); + MoveEffect* effect(const int index) throw(IndexException); + const MoveEffect* effectById(const int id) const throw(IndexException); + MoveEffect* effectById(const int id) throw(IndexException); + int effectIndex(const int id) const; + int effectCount() const; MoveEffect* newEffect(); - MoveEffect* newEffect(const QString& fname); - MoveEffect* newEffect(const MoveEffect& e); - void deleteEffect(const int i) throw(IndexException); + MoveEffect* newEffect(const QString& fileName); + MoveEffect* newEffect(const MoveEffect& effect); + void deleteEffect(const int index) throw(IndexException); + void deleteEffectById(const int id) throw(IndexException); Move& operator=(const Move& rhs); private: bool validate() const; - int getNewId() const; + int newEffectId() const; - QString name; - Frac accuracy; - int power; - int type; - bool special; - int powerPoints; - int target; - int numTargets; - int targetChoice; - bool ignoreAccuracy; - bool canFlinch; - bool canRandom; - bool canSnatch; - bool sound; - QString description; + QString m_name; + Frac m_accuracy; + int m_power; + int m_type; + bool m_special; + int m_powerPoints; + int m_target; + int m_numTargets; + int m_targetChoice; + bool m_ignoreAccuracy; + bool m_canFlinch; + bool m_canRandom; + bool m_canSnatch; + bool m_sound; + int m_priority; + QString m_description; - QList<MoveEffect*> effects; + QList<MoveEffect*> m_effects; }; #endif diff --git a/pokemod/MoveEffect.cpp b/pokemod/MoveEffect.cpp index 7db04244..afdb3dcb 100644 --- a/pokemod/MoveEffect.cpp +++ b/pokemod/MoveEffect.cpp @@ -1,239 +1,216 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MoveEffect.cpp -// Purpose: Define an effect of a move -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:29:40 2007 -// Copyright: ©2007 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Pokemod includes #include "Pokemod.h" + +// Header include #include "MoveEffect.h" const QStringList MoveEffect::EffectStr = QStringList() << "Damage" << "Status" << "Confuse" << "Stat" << "StealHP" << "Counter" << "Selfdestruct" << "Need Status" << "Mirror" << "GetMoney" << "Never Miss" << "Steal Types" << "Clear Effects" << "Wait And Return" << "Self Confuse" << "Force Switch" << "Hit Multiple" << "Hit Multiple Turns" << "Flinch" << "One Hit K.O." << "Recoil" << "Recover" << "Rest" << "Sheild" << "Substitute" << "Recharge" << "Rage" << "Mimic" << "Random Move" << "Seed" << "Disable" << "Cut HM" << "Fly HM" << "Surf HM" << "Strength HM" << "Flash HM" << "Rock Smash HM" << "Rock Climb HM" << "Whirlpool HM" << "Waterfall HM" << "Share HP HM " << "Escape HM"; -MoveEffect::MoveEffect(const Pokemod* par, const int _id) : - Object("MoveEffect", par, _id), - chance(1, 1), - effect(-1), - val1(-1), - val2(-1), - val3(0), - val4(1, 1) +MoveEffect::MoveEffect(const Pokemod* pokemod, const int id) : + Object("MoveEffect", pokemod, id), + m_chance(1, 1), + m_effect(INT_MAX), + m_value1(INT_MAX), + m_value2(INT_MAX), + m_value3(0), + m_value4(1, 1) { } -MoveEffect::MoveEffect(const Pokemod* par, const MoveEffect& e, const int _id) : - Object("MoveEffect", par, _id) +MoveEffect::MoveEffect(const Pokemod* pokemod, const MoveEffect& effect, const int id) : + Object("MoveEffect", pokemod, id) { - *this = e; + *this = effect; } -MoveEffect::MoveEffect(const Pokemod* par, const QString& fname, const int _id) : - Object("MoveEffect", par, _id) +MoveEffect::MoveEffect(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("MoveEffect", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool MoveEffect::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Effect with id %1---").arg(id), Pokemod::V_Msg); + pokemod()->validationMsg(QString("------Effect with id %1---").arg(id()), Pokemod::V_Msg); // TODO (Ben#1#): Move Effect validation return valid; } -void MoveEffect::load(const QString& fname, const int _id) throw(Exception) +void MoveEffect::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; int k; ini.getValue("chance-n", i, 1); ini.getValue("chance-d", j, 1); - chance.set(i, j); - ini.getValue("effect", effect); - ini.getValue("val1", val1); - ini.getValue("val2", val2); - ini.getValue("val3", val3); - ini.getValue("val4-n", i); - ini.getValue("val4-d", j); - ini.getValue("val4-t", k); - val4.set(i, j, k); + m_chance.set(i, j); + ini.getValue("effect", m_effect); + ini.getValue("value1", m_value1); + ini.getValue("value2", m_value2); + ini.getValue("value3", m_value3); + ini.getValue("value4-n", i); + ini.getValue("value4-d", j); + ini.getValue("value4-t", k); + m_value4.set(i, j, k); } void MoveEffect::save(const QString& move) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("chance-n", chance.getNum()); - ini.addField("chance-d", chance.getDenom()); - ini.addField("effect", effect); - ini.addField("val1", val1); - ini.addField("val2", val2); - ini.addField("val3", val3); - ini.addField("val4-n", val4.getNum()); - ini.addField("val4-d", val4.getDenom()); - ini.addField("val4-t", val4.getType()); - ini.save(QString("%1/move/%2/effect/%3.pini").arg(pokemod->getPath()).arg(move).arg(id)); -} - -void MoveEffect::setChance(const int n, const int d) throw(Exception) -{ - chance.set(n, d); -} - -void MoveEffect::setChanceNum(const int n) throw(Exception) -{ - chance.setNum(n); + ini.addField("id", id()); + ini.addField("chance-n", m_chance.numerator()); + ini.addField("chance-d", m_chance.denominator()); + ini.addField("effect", m_effect); + ini.addField("value1", m_value1); + ini.addField("value2", m_value2); + ini.addField("value3", m_value3); + ini.addField("value4-n", m_value4.numerator()); + ini.addField("value4-d", m_value4.denominator()); + ini.addField("value4-t", m_value4.type()); + ini.save(QString("%1/move/%2/effect/%3.pini").arg(pokemod()->path()).arg(move).arg(id())); } -void MoveEffect::setChanceDenom(const int d) throw(Exception) +void MoveEffect::setChance(const int numerator, const int denominator) throw(Exception) { - chance.setDenom(d); + m_chance.set(numerator, denominator); } -void MoveEffect::setEffect(const int e) throw(BoundsException) +void MoveEffect::setEffect(const int effect) throw(BoundsException) { - if (E_End <= e) - throw(BoundsException(className, "effect")); - effect = e; - val1 = -1; - val2 = -1; - val3 = 0; - val4.set(1, 1, ((e == E_StealHP) || (e == E_Counter) || (e == E_Selfdestruct) || (e == E_Mirror) || (e == E_GetMoney) || (e == E_WaitAndReturn) || (e == E_Recoil)) ? Frac::Improper : Frac::Proper); + if (E_End <= effect) + throw(BoundsException(className(), "effect")); + m_effect = effect; + m_value1 = INT_MAX; + m_value2 = INT_MAX; + m_value3 = 0; + m_value4.set(1, 1, ((effect == E_StealHP) || (effect == E_Counter) || (effect == E_Selfdestruct) || (effect == E_Mirror) || (effect == E_GetMoney) || (effect == E_WaitAndReturn) || (effect == E_Recoil)) ? Frac::Improper : Frac::Proper); } -void MoveEffect::setVal1(const int v1) throw(Exception) +void MoveEffect::setValue1(const int value1) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Damage: - if (D_End <= v1) - throw(BoundsException(className, "val1")); + if (D_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Status: case E_NeedStatus: - if (Pokemod::STS_End <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::STS_End <= value1) + throw(BoundsException(className(), "value1")); throw; case E_Stat: - if (Pokemod::ST_End_Battle <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::ST_End_Battle <= value1) + throw(BoundsException(className(), "value1")); break; case E_Counter: case E_Shield: - if (MT_End <= v1) - throw(BoundsException(className, "val1")); + if (MT_End <= value1) + throw(BoundsException(className(), "value1")); break; case E_Recoil: - if (R_End <= v1) - throw(BoundsException(className, "val1")); + if (R_End <= value1) + throw(BoundsException(className(), "value1")); break; default: - throw(BoundsException(className, "val1")); + throw(BoundsException(className(), "value1")); break; } - val1 = v1; + m_value1 = value1; } -void MoveEffect::setVal2(const int v2) throw(Exception) +void MoveEffect::setValue2(const int value2) throw(Exception) { - switch (effect) + switch (m_effect) { case E_Damage: - if ((D_Level <= val1) || !v2) - throw(BoundsException(className, "val2")); + if ((D_Level <= m_value1) || !value2) + throw(BoundsException(className(), "value2")); break; default: - throw(BoundsException(className, "val2")); + throw(BoundsException(className(), "value2")); break; } - val2 = v2; + m_value2 = value2; } -void MoveEffect::setVal3(const int v3) +void MoveEffect::setValue3(const int value3) { - switch (effect) + switch (m_effect) { case E_Damage: //if () break; } - val3 = v3; -} - -void MoveEffect::setVal4(const int n, const int d) throw(Exception) -{ - val4.set(n, d); -} - -void MoveEffect::setVal4Num(const int n) throw(Exception) -{ - val4.setNum(n); + m_value3 = value3; } -void MoveEffect::setVal4Denom(const int d) throw(Exception) +void MoveEffect::setValue4(const int numerator, const int denominator) throw(Exception) { - val4.setDenom(d); + m_value4.set(numerator, denominator); } -Frac MoveEffect::getChance() const +Frac MoveEffect::chance() const { - return chance; + return m_chance; } -int MoveEffect::getEffect() const +int MoveEffect::effect() const { - return effect; + return m_effect; } -int MoveEffect::getVal1() const +int MoveEffect::value1() const { - return val1; + return m_value1; } -int MoveEffect::getVal2() const +int MoveEffect::value2() const { - return val2; + return m_value2; } -int MoveEffect::getVal3() const +int MoveEffect::value3() const { - return val3; + return m_value3; } -Frac MoveEffect::getVal4() const +Frac MoveEffect::value4() const { - return val4; + return m_value4; } MoveEffect& MoveEffect::operator=(const MoveEffect& rhs) { if (this == &rhs) return *this; - chance = rhs.chance; - effect = rhs.effect; - val1 = rhs.val1; - val2 = rhs.val2; - val3 = rhs.val3; - val4 = rhs.val4; + m_chance = rhs.m_chance; + m_effect = rhs.m_effect; + m_value1 = rhs.m_value1; + m_value2 = rhs.m_value2; + m_value3 = rhs.m_value3; + m_value4 = rhs.m_value4; return *this; } diff --git a/pokemod/MoveEffect.h b/pokemod/MoveEffect.h index 4eb28a68..3ad84d87 100644 --- a/pokemod/MoveEffect.h +++ b/pokemod/MoveEffect.h @@ -1,36 +1,35 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/MoveEffect.h -// Purpose: Define an effect of a move -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:29:40 2007 -// Copyright: ©2007 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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_MOVEEFFECT__ #define __POKEMOD_MOVEEFFECT__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class MoveEffect : public Object @@ -113,41 +112,37 @@ class MoveEffect : public Object }; static const QStringList RecoilStr; - MoveEffect(const Pokemod* par, const int _id); - MoveEffect(const Pokemod* par, const MoveEffect& e, const int _id); - MoveEffect(const Pokemod* par, const QString& fname, const int _id = -1); + MoveEffect(const Pokemod* pokemod, const int id); + MoveEffect(const Pokemod* pokemod, const MoveEffect& effect, const int id); + MoveEffect(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& move) const throw(Exception); - void setChance(const int n, const int d) throw(Exception); - void setChanceNum(const int n) throw(Exception); - void setChanceDenom(const int d) throw(Exception); - void setEffect(const int e) throw(BoundsException); - void setVal1(const int v1) throw(Exception); - void setVal2(const int v2) throw(Exception); - void setVal3(const int v3); - void setVal4(const int n, const int d) throw(Exception); - void setVal4Num(const int n) throw(Exception); - void setVal4Denom(const int d) throw(Exception); + void setChance(const int numerator, const int denominator) throw(Exception); + void setEffect(const int effect) throw(BoundsException); + void setValue1(const int value1) throw(Exception); + void setValue2(const int value2) throw(Exception); + void setValue3(const int value3); + void setValue4(const int numerator, const int denominator) throw(Exception); - Frac getChance() const; - int getEffect() const; - int getVal1() const; - int getVal2() const; - int getVal3() const; - Frac getVal4() const; + Frac chance() const; + int effect() const; + int value1() const; + int value2() const; + int value3() const; + Frac value4() const; MoveEffect& operator=(const MoveEffect& rhs); private: bool validate() const; - Frac chance; - int effect; - int val1; - int val2; - int val3; - Frac val4; + Frac m_chance; + int m_effect; + int m_value1; + int m_value2; + int m_value3; + Frac m_value4; }; #endif diff --git a/pokemod/Nature.cpp b/pokemod/Nature.cpp index fa52ef43..c1b0f834 100644 --- a/pokemod/Nature.cpp +++ b/pokemod/Nature.cpp @@ -1,155 +1,138 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Nature.cpp -// Purpose: Define a nature that species can possess -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sun Mar 18 22:58:48 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Pokemod includes #include "Pokemod.h" + +// Header include #include "Nature.h" -Nature::Nature(const Pokemod* par, const int _id) : - Object("Nature", par, _id), - name(""), - weight(1) +Nature::Nature(const Pokemod* pokemod, const int id) : + Object("Nature", pokemod, id), + m_name(""), + m_weight(1) { for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - stats[i].set(1, 1, Frac::Improper); + m_stats[i].set(1, 1, Frac::Improper); } -Nature::Nature(const Pokemod* par, const Nature& n, const int _id) : - Object("Nature", par, _id) +Nature::Nature(const Pokemod* pokemod, const Nature& nature, const int id) : + Object("Nature", pokemod, id) { - *this = n; + *this = nature; } -Nature::Nature(const Pokemod* par, const QString& fname, const int _id) : - Object("Nature", par, _id) +Nature::Nature(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Nature", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Nature::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Nature \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Nature \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (!weight) + if (!m_weight) { - pokemod->validationMsg("Weight is not valid"); + pokemod()->validationMsg("Weight is not valid"); valid = false; } return valid; } -void Nature::load(const QString& fname, const int _id) throw(Exception) +void Nature::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); for (int k = 0; k < Pokemod::ST_End_GSC; ++k) { ini.getValue(QString("stat-%1-n").arg(k), i, 1); ini.getValue(QString("stat-%1-n").arg(k), j, 1); - stats[k].set(1, 1, true); + m_stats[k].set(1, 1, true); } - ini.getValue("weight", weight); + ini.getValue("weight", m_weight); } void Nature::save() const throw(Exception) { Ini ini; - ini.addField("name", name); + ini.addField("name", m_name); for (int i = 0; i < Pokemod::ST_End_GSC; ++i) { - ini.addField(QString("stat-%1-n").arg(i), stats[i].getNum()); - ini.addField(QString("stat-%1-d").arg(i), stats[i].getNum()); + ini.addField(QString("stat-%1-n").arg(i), m_stats[i].numerator()); + ini.addField(QString("stat-%1-d").arg(i), m_stats[i].denominator()); } - ini.addField("weight", weight); - ini.save(QString("%1/nature/%2.pini").arg(pokemod->getPath()).arg(name)); -} - -void Nature::setName(const QString& n) -{ - name = n; + ini.addField("weight", m_weight); + ini.save(QString("%1/nature/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Nature::setStat(const int s, const int n, const int d) throw(Exception) +void Nature::setName(const QString& name) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].set(n, d); + m_name = name; } -void Nature::setStatNum(const int s, const int n) throw(Exception) +void Nature::setStat(const int stat, const int numerator, const int denominator) throw(Exception) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].setNum(n); + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) + throw(BoundsException(className(), "stat")); + m_stats[stat].set(numerator, denominator); } -void Nature::setStatDenom(const int s, const int d) throw(Exception) +void Nature::setWeight(const int weight) throw(BoundsException) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - stats[s].setDenom(d); -} - -void Nature::setWeight(const int w) throw(BoundsException) -{ - if (!w) - throw(BoundsException(className, "weight")); - weight = w; + if (!weight) + throw(BoundsException(className(), "weight")); + m_weight = weight; } -QString Nature::getName() const +QString Nature::name() const { - return name; + return m_name; } -Frac Nature::getStat(const int s) const throw(BoundsException) +Frac Nature::stat(const int stat) const throw(BoundsException) { - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= s) - throw(BoundsException(className, "stat")); - return stats[s]; + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= stat) + throw(BoundsException(className(), "stat")); + return m_stats[stat]; } -int Nature::getWeight() const +int Nature::weight() const { - return weight; + return m_weight; } Nature& Nature::operator=(const Nature& rhs) { if (this == &rhs) return *this; - name = rhs.name; + m_name = rhs.m_name; for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - stats[i] = rhs.stats[i]; - weight = rhs.weight; + m_stats[i] = rhs.m_stats[i]; + m_weight = rhs.m_weight; return *this; } diff --git a/pokemod/Nature.h b/pokemod/Nature.h index 53732a57..633a6ec2 100644 --- a/pokemod/Nature.h +++ b/pokemod/Nature.h @@ -1,63 +1,61 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Nature.h -// Purpose: Define a nature that species can possess -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sun Mar 18 22:58:48 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" -#include "Pokemod.h" + +// Forward declarations +class Pokemod; class Nature : public Object { public: - Nature(const Pokemod* par, const int _id); - Nature(const Pokemod* par, const Nature& n, const int _id); - Nature(const Pokemod* par, const QString& fname, const int _id = -1); + Nature(const Pokemod* pokemod, const int id); + Nature(const Pokemod* pokemod, const Nature& nature, const int id); + Nature(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setStat(const int s, const int n, const int d) throw(Exception); - void setStatNum(const int s, const int n) throw(Exception); - void setStatDenom(const int s, const int d) throw(Exception); - void setWeight(const int w) throw(BoundsException); + void setName(const QString& name); + void setStat(const int stat, const int numerator, const int denominator) throw(Exception); + void setWeight(const int weight) throw(BoundsException); - QString getName() const; - Frac getStat(const int s) const throw(BoundsException); - int getWeight() const; + QString name() const; + Frac stat(const int stat) const throw(BoundsException); + int weight() const; Nature& operator=(const Nature& rhs); private: bool validate() const; - QString name; - Frac stats[Pokemod::ST_End_GSC]; - int weight; + QString m_name; + Frac m_stats[Pokemod::ST_End_GSC]; + int m_weight; }; #endif diff --git a/pokemod/Object.h b/pokemod/Object.h index a0c774ef..07555724 100644 --- a/pokemod/Object.h +++ b/pokemod/Object.h @@ -31,25 +31,25 @@ class Pokemod; class Object { public: - Object(const QString& name, const Pokemod* par, const int _id) : - id(_id), - className(name), - pokemod(par) + Object(const QString& className, const Pokemod* pokemod, const int id) : + mid(id), + m_className(className), + m_pokemod(pokemod) { } virtual ~Object() { } - virtual void load(const QString& fname, const int _id = -1) throw(Exception) = 0; + virtual void load(const QString& fileName, int id = INT_MAX) throw(Exception) = 0; - const Pokemod* getPokemod() const + const Pokemod* pokemod() const { - return pokemod; + return m_pokemod; } - int getId() const + int id() const { - return id; + return mid; } bool isValid() const { @@ -59,20 +59,23 @@ class Object } bool isGood() const { - return (0 <= id); + return (0 <= mid); } - QString getClassName() const + QString className() const { - return className; + return m_className; } protected: + void setId(const int id) + { + mid = id; + } virtual bool validate() const = 0; - - int id; - const QString className; - - const Pokemod* pokemod; + private: + int mid; + const QString m_className; + const Pokemod* m_pokemod; }; #endif diff --git a/pokemod/Pokemod.cpp b/pokemod/Pokemod.cpp index 6add7b59..3de5b185 100644 --- a/pokemod/Pokemod.cpp +++ b/pokemod/Pokemod.cpp @@ -1,33 +1,27 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Pokemod.cpp -// Purpose: Define a custom PokéMod for PokéGen -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sat Feb 24 21:41:19 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> -#include <QStringListIterator> #include <QTextStream> #include <QTime> +// Pokemod includes #include "Ability.h" #include "Author.h" #include "Badge.h" @@ -45,6 +39,8 @@ #include "Time.h" #include "Trainer.h" #include "Type.h" + +// Header include #include "Pokemod.h" const QStringList Pokemod::ValidationStr = QStringList() << "Message" << "Warn" << "Error"; @@ -60,97 +56,95 @@ const QStringList Pokemod::HMStr = QStringList() << "Cut" << "Fly" << "Surf" << Pokemod::Pokemod() : Object("Pokemod", this, 0), valOutput(NULL), - title(""), - version(""), - description(""), - startMap(-1), - startWarp(-1), - superPCUname(""), - superPCPasswd(""), - typeChart(1, 1, Frac(1, 1, Frac::Improper)), - rules(this), - path(QString("%1/.kde/share/apps/pokegen/mods").arg(QDir::homePath())) + m_title(""), + m_version(""), + m_description(""), + m_startMap(INT_MAX), + m_startWarp(INT_MAX), + m_superPCUname(""), + m_superPCPasswd(""), + m_typeChart(1, 1, Frac(1, 1, Frac::Improper)), + m_rules(this), + m_path(QString("%1/.kde/share/apps/pokegen/mods").arg(QDir::homePath())) { } -Pokemod::Pokemod(const Pokemod& p) : +Pokemod::Pokemod(const Pokemod& pokemod) : Object("Pokemod", this, 0), - rules(this) + m_rules(this) { - *this = p; + *this = pokemod; } -Pokemod::Pokemod(const QString& fname) : +Pokemod::Pokemod(const QString& fileName) : Object("Pokemod", this, 0), valOutput(NULL), - title(""), - version(""), - description(""), - startMap(-1), - startWarp(-1), - superPCUname(""), - superPCPasswd(""), - typeChart(1, 1, Frac(1, 1, Frac::Improper)), - rules(this) + m_title(""), + m_version(""), + m_description(""), + m_startMap(INT_MAX), + m_startWarp(INT_MAX), + m_superPCUname(""), + m_superPCPasswd(""), + m_typeChart(1, 1, Frac(1, 1, Frac::Improper)), + m_rules(this) { - load(fname); + load(fileName); } Pokemod::~Pokemod() { - for (QListIterator<Ability*> i(abilities); i.hasNext(); ) - delete i.next(); - for (QListIterator<Author*> i(authors); i.hasNext(); ) - delete i.next(); - for (QListIterator<Badge*> i(badges); i.hasNext(); ) - delete i.next(); - for (QListIterator<CoinList*> i(coinLists); i.hasNext(); ) - delete i.next(); - for (QListIterator<Dialog*> i(dialogs); i.hasNext(); ) - delete i.next(); - for (QListIterator<EggGroup*> i(eggGroups); i.hasNext(); ) - delete i.next(); - for (QListIterator<Item*> i(items); i.hasNext(); ) - delete i.next(); - for (QListIterator<ItemType*> i(itemTypes); i.hasNext(); ) - delete i.next(); - for (QListIterator<Map*> i(maps); i.hasNext(); ) - delete i.next(); - for (QListIterator<Nature*> i(natures); i.hasNext(); ) - delete i.next(); - for (QListIterator<Species*> i(species); i.hasNext(); ) - delete i.next(); - for (QListIterator<Store*> i(stores); i.hasNext(); ) - delete i.next(); - for (QListIterator<Tile*> i(tiles); i.hasNext(); ) - delete i.next(); - for (QListIterator<Time*> i(times); i.hasNext(); ) - delete i.next(); - for (QListIterator<Trainer*> i(trainers); i.hasNext(); ) - delete i.next(); - for (QListIterator<Type*> i(types); i.hasNext(); ) - delete i.next(); + foreach (Ability* ability, m_abilities) + delete ability; + foreach (Author* author, m_authors) + delete author; + foreach (Badge* badge, m_badges) + delete badge; + foreach (CoinList* coinList, m_coinLists) + delete coinList; + foreach (Dialog* dialog, m_dialogs) + delete dialog; + foreach (EggGroup* eggGroup, m_eggGroups) + delete eggGroup; + foreach (Item* item, m_items) + delete item; + foreach (ItemType* itemType, m_itemTypes) + delete itemType; + foreach (Map* map, m_maps) + delete map; + foreach (Species* m_species, m_species) + delete m_species; + foreach (Store* store, m_stores) + delete store; + foreach (Tile* tile, m_tiles) + delete tile; + foreach (Time* time, m_times) + delete time; + foreach (Trainer* trainer, m_trainers) + delete trainer; + foreach (Type* type, m_types) + delete type; } bool Pokemod::validate() const { bool valid = true; - validationMsg(QString("Pokemod \"%1\"").arg(title), V_Msg); - if (title == "") + validationMsg(QString("Pokemod \"%1\"").arg(m_title), V_Msg); + if (m_title == "") { validationMsg("Title is not defined"); valid = false; } - if (version == "") + if (m_version == "") { validationMsg("Version is not defined"); valid = false; } - if (description == "") + if (m_description == "") validationMsg("Description is not defined", V_Warn); - if (getMapIndex(startMap)) + if (mapIndex(m_startMap)) { - if (getMapByID(startMap)->getWarpIndex(startWarp) == -1) + if (mapById(m_startMap)->warpIndex(m_startWarp) == INT_MAX) { validationMsg("Invalid starting warp"); valid = false; @@ -161,831 +155,433 @@ bool Pokemod::validate() const validationMsg("Invalid starting map"); valid = false; } - if (!QFile::exists(getWalkSkin())) + if (!QFile::exists(walkSkin())) { validationMsg("Cannot find walking skin"); valid = false; } - if (!QFile::exists(getBikeSkin())) + if (!QFile::exists(bikeSkin())) { validationMsg("Cannot find biking skin"); valid = false; } - if (!QFile::exists(getSurfSkin())) + if (!QFile::exists(surfSkin())) { validationMsg("Cannot find surfing skin"); valid = false; } - if (!QFile::exists(getFlySkin())) + if (!QFile::exists(flySkin())) { validationMsg("Cannot find flying skin"); valid = false; } - if (!QFile::exists(getFishSkin())) + if (!QFile::exists(fishSkin())) { validationMsg("Cannot find fishing skin"); valid = false; } - if (!QFile::exists(getSurfFishSkin())) + if (!QFile::exists(surfFishSkin())) { validationMsg("Cannot find surf fishing skin"); valid = false; } - if (superPCUname == "") + if (m_superPCUname == "") validationMsg("Super PC username not defined", V_Warn); - if (superPCPasswd == "") + if (m_superPCPasswd == "") validationMsg("Super PC password not defined", V_Warn); - if ((typeChart.getWidth() != getTypeCount()) || (typeChart.getHeight() != getTypeCount())) + if ((m_typeChart.width() != typeCount()) || (m_typeChart.height() != typeCount())) { validationMsg("TypeChart is invalid"); valid = false; } - if (!rules.isValid()) + if (!m_rules.isValid()) valid = false; - QMap<int, int> idChecker; - QMap<QString, int> nameChecker; - QMap<int, int> timeChecker; - if (rules.getAbilityAllowed()) + QMap<int, bool> idChecker; + QMap<int, bool> timeChecker; + if (m_rules.abilityAllowed()) { - if (!getAbilityCount()) + if (!abilityCount()) { validationMsg("There are no abilities"); valid = false; } - for (QListIterator<Ability*> i(abilities); i.hasNext(); i.next()) + foreach (Ability* ability, m_abilities) { - if (!i.peekNext()->isValid()) + if (!ability->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 abilities with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 abilities with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[ability->id()]) + validationMsg(QString("Duplicate ability with id %1").arg(ability->id())); + idChecker[ability->id()] = true; } idChecker.clear(); - nameChecker.clear(); } - if (!getAuthorCount()) + if (!authorCount()) { validationMsg("There are no authors"); valid = false; } - for (QListIterator<Author*> i(authors); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 authors with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) + foreach (Author* author, m_authors) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 authors with the name \"%2\"").arg(i.value()).arg(i.key())); + if (!author->isValid()) valid = false; - } + if (idChecker[author->id()]) + validationMsg(QString("Duplicate author with id %1").arg(author->id())); + idChecker[author->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getBadgeCount()) + if (!badgeCount()) validationMsg("There are no badges", V_Warn); - for (QListIterator<Badge*> i(badges); i.hasNext(); i.next()) + foreach (Badge* badge, m_badges) { - if (!i.peekNext()->isValid()) + if (!badge->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 badges with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 badges with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[badge->id()]) + validationMsg(QString("Duplicate badge with id %1").arg(badge->id())); + idChecker[badge->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getCoinListCount()) + if (!coinListCount()) validationMsg("There are no coin lists", V_Warn); - for (QListIterator<CoinList*> i(coinLists); i.hasNext(); i.next()) + foreach (CoinList* coinList, m_coinLists) { - if (!i.peekNext()->isValid()) + if (!coinList->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 coin lists with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 coin lists with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[coinList->id()]) + validationMsg(QString("Duplicate coin list with id %1").arg(coinList->id())); + idChecker[coinList->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getDialogCount()) + if (!dialogCount()) { validationMsg("There are no dialogs"); valid = false; } - for (QListIterator<Dialog*> i(dialogs); i.hasNext(); i.next()) + foreach (Dialog* dialog, m_dialogs) { - if (!i.peekNext()->isValid()) + if (!dialog->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 dialogs with id %2").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[dialog->id()]) + validationMsg(QString("Duplicate dialog with id %1").arg(dialog->id())); + idChecker[dialog->id()] = true; } idChecker.clear(); - if (rules.getBreedingAllowed()) + if (m_rules.breedingAllowed()) { - if (!getEggGroupCount()) + if (!eggGroupCount()) { validationMsg("There are no egg grous"); valid = false; } - for (QListIterator<EggGroup*> i(eggGroups); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 egg groups with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) + foreach (EggGroup* eggGroup, m_eggGroups) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 egg groups with the name \"%2\"").arg(i.value()).arg(i.key())); + if (!eggGroup->isValid()) valid = false; - } + if (idChecker[eggGroup->id()]) + validationMsg(QString("Duplicate egg group with id %1").arg(eggGroup->id())); + idChecker[eggGroup->id()] = true; } idChecker.clear(); - nameChecker.clear(); - } - if (!getItemCount()) - validationMsg("There are no items", V_Warn); - for (QListIterator<Item*> i(items); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + if (!itemCount()) + validationMsg("There are no m_items", V_Warn); + foreach (Item* item, m_items) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 items with id %2").arg(i.value()).arg(i.key())); + if (!item->isValid()) valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 items with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[item->id()]) + validationMsg(QString("Duplicate item with id %1").arg(item->id())); + idChecker[item->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getItemTypeCount()) - { - validationMsg("There are no item types", getItemCount() ? V_Error : V_Warn); - if (getItemCount()) - valid = false; - } - for (QListIterator<ItemType*> i(itemTypes); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + if (!itemTypeCount()) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 item types with id %2").arg(i.value()).arg(i.key())); + validationMsg("There are no item types", itemCount() ? V_Error : V_Warn); + if (itemCount()) valid = false; - } } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) + foreach (ItemType* itemType, m_itemTypes) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 item types with the name \"%2\"").arg(i.value()).arg(i.key())); + if (!itemType->isValid()) valid = false; - } + if (idChecker[itemType->id()]) + validationMsg(QString("Duplicate item type with id %1").arg(itemType->id())); + idChecker[itemType->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getMapCount()) + if (!mapCount()) { - validationMsg("There are no maps"); + validationMsg("There are no m_maps"); valid = false; } - for (QListIterator<Map*> i(maps); i.hasNext(); i.next()) + foreach (Map* map, m_maps) { - if (!i.peekNext()->isValid()) + if (!map->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 maps with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 maps with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[map->id()]) + validationMsg(QString("Duplicate map with id %1").arg(map->id())); + idChecker[map->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getMoveCount()) + if (!moveCount()) { - validationMsg("There are no moves"); + validationMsg("There are no m_moves"); valid = false; } - for (QListIterator<Move*> i(moves); i.hasNext(); i.next()) + foreach (Move* move, m_moves) { - if (!i.peekNext()->isValid()) + if (!move->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 moves with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 moves with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[move->id()]) + validationMsg(QString("Duplicate move with id %1").arg(move->id())); + idChecker[move->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (rules.getNatureAllowed()) + if (m_rules.natureAllowed()) { - if (!getNatureCount()) + if (!natureCount()) { validationMsg("There are no natures"); valid = false; } - for (QListIterator<Nature*> i(natures); i.hasNext(); i.next()) + foreach (Nature* nature, m_natures) { - if (!i.peekNext()->isValid()) + if (!nature->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 natures with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 natures with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[nature->id()]) + validationMsg(QString("Duplicate ability with id %1").arg(nature->id())); + idChecker[nature->id()] = true; } idChecker.clear(); - nameChecker.clear(); } - if (!getSpeciesCount()) + if (!speciesCount()) { - validationMsg("There are no species"); + validationMsg("There are no m_species"); valid = false; } - for (QListIterator<Species*> i(species); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 species with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) + foreach (Species* m_species, m_species) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 species with the name \"%2\"").arg(i.value()).arg(i.key())); + if (!m_species->isValid()) valid = false; - } + if (idChecker[m_species->id()]) + validationMsg(QString("Duplicate m_species with id %1").arg(m_species->id())); + idChecker[m_species->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getStoreCount()) - validationMsg("There are no stores", V_Warn); - for (QListIterator<Store*> i(stores); i.hasNext(); i.next()) + if (!storeCount()) + validationMsg("There are no m_stores", V_Warn); + foreach (Store* store, m_stores) { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 stores with id %2").arg(i.value()).arg(i.key())); + if (!store->isValid()) valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 stores with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[store->id()]) + validationMsg(QString("Duplicate store with id %1").arg(store->id())); + idChecker[store->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (getTileCount()) - { - for (QListIterator<Tile*> i(tiles); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 tiles with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 tiles with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } - } - idChecker.clear(); - nameChecker.clear(); - } - else + if (!tileCount()) { - validationMsg("There are no tiles"); + validationMsg("There are no m_tiles"); valid = false; } - if (!getTrainerCount()) + foreach (Tile* tile, m_tiles) { - validationMsg("There are no times", Pokemod::V_Warn); - } - for (QListIterator<Trainer*> i(trainers); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) + if (!tile->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; + if (idChecker[tile->id()]) + validationMsg(QString("Duplicate tile with id %1").arg(tile->id())); + idChecker[tile->id()] = true; } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) + idChecker.clear(); + if (!trainerCount()) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 trainers with id %2").arg(i.value()).arg(i.key())); - valid = false; - } + validationMsg("There are no times", Pokemod::V_Warn); } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) + foreach (Trainer* trainer, m_trainers) { - if (1 < i.value()) - { - validationMsg(QString("There are %1 trianers with the name \"%2\"").arg(i.value()).arg(i.key())); + if (!trainer->isValid()) valid = false; - } + if (idChecker[trainer->id()]) + validationMsg(QString("Duplicate trainer with id %1").arg(trainer->id())); + idChecker[trainer->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getTimeCount()) + if (!timeCount()) { validationMsg("There are no times"); valid = false; } - for (QListIterator<Time*> i(times); i.hasNext(); i.next()) + foreach (Time* time, m_times) { - if (!i.peekNext()->isValid()) + if (!time->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - ++timeChecker[(60 * i.peekNext()->getStartHour()) + i.peekNext()->getStartMinute()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 times with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 times with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<int, int> i(timeChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 times that start at %2:%3").arg(i.value()).arg(i.key() / 60).arg(i.key() % 60)); - valid = false; - } + if (idChecker[time->id()]) + validationMsg(QString("Duplicate time with id %1").arg(time->id())); + idChecker[time->id()] = true; + if (timeChecker[(60 * time->hour()) + time->minute()]) + validationMsg(QString("Duplicate time at %1:%2").arg(time->hour()).arg(time->minute())); + timeChecker[(60 * time->hour()) + time->minute()] = true; } idChecker.clear(); - nameChecker.clear(); - if (!getTypeCount()) + if (!typeCount()) { validationMsg("There are no types"); valid = false; } - for (QListIterator<Type*> i(types); i.hasNext(); i.next()) + foreach (Type* type, m_types) { - if (!i.peekNext()->isValid()) + if (!type->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getName()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 types with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<QString, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - validationMsg(QString("There are %1 types with the name \"%2\"").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[type->id()]) + validationMsg(QString("Duplicate type with id %1").arg(type->id())); + idChecker[type->id()] = true; } return valid; } -int Pokemod::getNewAbilityId() const -{ - int i = 0; - for (; (i < getAbilityCount()) && (getAbilityIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewAuthorId() const -{ - int i = 0; - for (; (i < getAuthorCount()) && (getAuthorIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewBadgeId() const -{ - int i = 0; - for (; (i < getBadgeCount()) && (getBadgeIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewCoinListId() const -{ - int i = 0; - for (; (i < getCoinListCount()) && (getCoinListIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewDialogId() const -{ - int i = 0; - for (; (i < getDialogCount()) && (getDialogIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewEggGroupId() const -{ - int i = 0; - for (; (i < getEggGroupCount()) && (getEggGroupIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewItemId() const -{ - int i = 0; - for (; (i < getItemCount()) && (getItemIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewItemTypeId() const -{ - int i = 0; - for (; (i < getItemTypeCount()) && (getItemTypeIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewMapId() const -{ - int i = 0; - for (; (i < getMapCount()) && (getMapIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewMoveId() const -{ - int i = 0; - for (; (i < getMoveCount()) && (getMoveIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewNatureId() const -{ - int i = 0; - for (; (i < getNatureCount()) && (getNatureIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewSpeciesId() const -{ - int i = 0; - for (; (i < getSpeciesCount()) && (getSpeciesIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewStoreId() const -{ - int i = 0; - for (; (i < getStoreCount()) && (getStoreIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewTileId() const -{ - int i = 0; - for (; (i < getTileCount()) && (getTileIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewTimeId() const -{ - int i = 0; - for (; (i < getTimeCount()) && (getTimeIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewTrainerId() const -{ - int i = 0; - for (; (i < getTrainerCount()) && (getTrainerIndex(i) != -1); ++i) - ; - return i; -} - -int Pokemod::getNewTypeId() const -{ - int i = 0; - for (; (i < getTypeCount()) && (getTypeIndex(i) != -1); ++i) - ; - return i; -} - -void Pokemod::load(const QString& fname, const int) throw(Exception) -{ - Ini ini(fname); - path = fname.split('\\', QString::SkipEmptyParts).join("/").split("/", QString::SkipEmptyParts).join("/"); - ini.getValue("title", title); - ini.getValue("version", version); - ini.getValue("description", description); - ini.getValue("startMap", startMap); - ini.getValue("startWarp", startWarp); - ini.getValue("superPCUname", superPCUname); - ini.getValue("superPCPasswd", superPCPasswd); - QDir fdir(getPath()); - if (QFile::exists(QString("%1/rules.pini").arg(getPath()))) - rules.load(QString("%1/rules.pini").arg(getPath())); - abilities.clear(); +void Pokemod::load(const QString& fileName, const int) throw(Exception) +{ + Ini ini(fileName); + m_path = fileName.split('\\', QString::SkipEmptyParts).join("/").split("/", QString::SkipEmptyParts).join("/"); + ini.getValue("title", m_title); + ini.getValue("version", m_version); + ini.getValue("description", m_description); + ini.getValue("startMap", m_startMap); + ini.getValue("startWarp", m_startWarp); + ini.getValue("superPCUname", m_superPCUname); + ini.getValue("superPCPasswd", m_superPCPasswd); + QDir fdir(path()); + if (QFile::exists(QString("%1/rules.pini").arg(path()))) + m_rules.load(QString("%1/rules.pini").arg(path())); + m_abilities.clear(); if (fdir.cd("ability")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newAbility(QString("%1/data.pini").arg(i.next())); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newAbility(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - authors.clear(); + m_authors.clear(); if (fdir.cd("author")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newAuthor(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newAuthor(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - badges.clear(); + m_badges.clear(); if (fdir.cd("badge")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newBadge(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newBadge(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - coinLists.clear(); + m_coinLists.clear(); if (fdir.cd("coinlist")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newCoinList(QString("%1/data.pini").arg(i.next())); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newCoinList(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - dialogs.clear(); + m_dialogs.clear(); if (fdir.cd("dialog")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newDialog(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newDialog(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - eggGroups.clear(); + m_eggGroups.clear(); if (fdir.cd("egggroup")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newEggGroup(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newEggGroup(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - items.clear(); + m_items.clear(); if (fdir.cd("item")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newItem(QString("%1/data.pini").arg(i.next())); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newItem(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - itemTypes.clear(); + m_itemTypes.clear(); if (fdir.cd("itemtype")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newItemType(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newItemType(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - maps.clear(); + m_maps.clear(); if (fdir.cd("map")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newMap(QString("%1/data.pini").arg(i.next())); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newMap(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - moves.clear(); + m_moves.clear(); if (fdir.cd("move")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newMove(QString("%1/data.pini").arg(i.next())); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newMove(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - natures.clear(); + m_natures.clear(); if (fdir.cd("nature")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newNature(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newNature(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - species.clear(); - if (fdir.cd("species")) + m_species.clear(); + if (fdir.cd("m_species")) { - for (QStringListIterator i(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); i.hasNext(); ) - newSpecies(QString("%1/data.pini").arg(i.next())); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newSpecies(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - stores.clear(); + m_stores.clear(); if (fdir.cd("store")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newStore(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newStore(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - tiles.clear(); + m_tiles.clear(); if (fdir.cd("tile")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newTile(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newTile(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - trainers.clear(); + m_trainers.clear(); if (fdir.cd("trainer")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newTrainer(i.next()); - fdir.cdUp(); - } - trainers.clear(); - if (fdir.cd("time")) - { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newTime(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newTrainer(QString("%1/data.pini").arg(dir)); fdir.cdUp(); } - types.clear(); + m_types.clear(); if (fdir.cd("type")) { - for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) - newType(i.next()); + QStringList dirs(fdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name)); + foreach (QString dir, dirs) + newType(QString("%1/data.pini").arg(dir)); } - for (int i = 0; i < getTypeCount(); ++i) + for (int i = 0; i < typeCount(); ++i) { - for (int j = 0; j < getTypeCount(); ++j) + for (int j = 0; j < typeCount(); ++j) { int k; int l; @@ -999,68 +595,64 @@ void Pokemod::load(const QString& fname, const int) throw(Exception) void Pokemod::save() const throw(Exception) { Ini ini; - ini.addField("title", title); - ini.addField("version", version); - ini.addField("description", description); - ini.addField("startMap", startMap); - ini.addField("startWarp", startWarp); - ini.addField("superPCUname", superPCUname); - ini.addField("superPCPasswd", superPCPasswd); - for (int i = 1; i < typeChart.getWidth(); ++i) - { - for (int j = 1; j < typeChart.getHeight(); ++j) + ini.addField("title", m_title); + ini.addField("version", m_version); + ini.addField("description", m_description); + ini.addField("startMap", m_startMap); + ini.addField("startWarp", m_startWarp); + ini.addField("superPCUname", m_superPCUname); + ini.addField("superPCPasswd", m_superPCPasswd); + for (int i = 1; i < m_typeChart.width(); ++i) + { + for (int j = 1; j < m_typeChart.height(); ++j) { - ini.addField(QString("typeChart-%1-%2-n").arg(typeChart(i, 0).getNum()).arg(typeChart(0, j).getNum()), typeChart(i, j).getNum()); - ini.addField(QString("typeChart-%1-%2-d").arg(typeChart(i, 0).getNum()).arg(typeChart(0, j).getNum()), typeChart(i, j).getDenom()); + ini.addField(QString("typeChart-%1-%2-n").arg(i).arg(j), m_typeChart(i, j).numerator()); + ini.addField(QString("typeChart-%1-%2-d").arg(i).arg(j), m_typeChart(i, j).denominator()); } } - ini.save(QString("%1/data.pini").arg(getPath())); - rules.save(); - for (QListIterator<Ability*> i(abilities); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Author*> i(authors); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Badge*> i(badges); i.hasNext(); ) - i.next()->save(); - for (QListIterator<CoinList*> i(coinLists); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Dialog*> i(dialogs); i.hasNext(); ) - i.next()->save(); - for (QListIterator<EggGroup*> i(eggGroups); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Item*> i(items); i.hasNext(); ) - i.next()->save(); - for (QListIterator<ItemType*> i(itemTypes); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Map*> i(maps); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Move*> i(moves); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Nature*> i(natures); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Species*> i(species); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Store*> i(stores); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Tile*> i(tiles); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Time*> i(times); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Trainer*> i(trainers); i.hasNext(); ) - i.next()->save(); - for (QListIterator<Type*> i(types); i.hasNext(); ) - i.next()->save(); -} - -QString Pokemod::getPath() const -{ - return path; -} - -void Pokemod::setPath(const QString& p) -{ - copyDir(path, p); - path = p; + ini.save(QString("%1/data.pini").arg(path())); + m_rules.save(); + foreach (Ability* ability, m_abilities) + ability->save(); + foreach (Author* author, m_authors) + author->save(); + foreach (Badge* badge, m_badges) + badge->save(); + foreach (CoinList* coinList, m_coinLists) + coinList->save(); + foreach (Dialog* dialog, m_dialogs) + dialog->save(); + foreach (EggGroup* eggGroup, m_eggGroups) + eggGroup->save(); + foreach (Item* item, m_items) + item->save(); + foreach (ItemType* itemType, m_itemTypes) + itemType->save(); + foreach (Map* map, m_maps) + map->save(); + foreach (Species* m_species, m_species) + m_species->save(); + foreach (Store* store, m_stores) + store->save(); + foreach (Tile* tile, m_tiles) + tile->save(); + foreach (Time* time, m_times) + time->save(); + foreach (Trainer* trainer, m_trainers) + trainer->save(); + foreach (Type* type, m_types) + type->save(); +} + +QString Pokemod::path() const +{ + return m_path; +} + +void Pokemod::setPath(const QString& path) +{ + copyDir(m_path, path); + m_path = path; } void Pokemod::copyDir(const QString& src, const QString& dest) const @@ -1073,7 +665,7 @@ void Pokemod::copyDir(const QString& src, const QString& dest) const QFile::copy(QString("%1/%2").arg(src).arg(list[i]), QString("%1/%2").arg(dest).arg(list[i])); } -int Pokemod::maxCompatability(const Pokemod& p) const +int Pokemod::maxCompatability(const Pokemod& pokemod) const { // TODO (Ben #1#): MaxCompatability between two versions } @@ -1081,9 +673,9 @@ int Pokemod::maxCompatability(const Pokemod& p) const void Pokemod::validationMsg(const QString& msg, Validation val) const throw(Exception) { if (!valOutput) - throw(Exception(className, "valOutput isn\'t set")); + throw(Exception(className(), "valOutput isn\'t set")); if (V_End < val) - throw(BoundsException(className, "val")); + throw(BoundsException(className(), "val")); (*valOutput) << ValidationStr[val] << QDateTime::currentDateTime().toString(" (yyyyMMdd hh:mm:ss.zzz ddd): ") << msg; } @@ -1097,1395 +689,1599 @@ void Pokemod::unsetValOutput() valOutput = NULL; } -void Pokemod::setTitle(const QString& t) +void Pokemod::setTitle(const QString& title) { - title = t; + m_title = title; } -void Pokemod::setVersion(const QString& v) +void Pokemod::setVersion(const QString& version) { - version = v; + m_version = version; } -void Pokemod::setDescription(const QString& d) +void Pokemod::setDescription(const QString& description) { - description = d; + m_description = description; } -void Pokemod::setStartMap(const int s) throw(BoundsException) +void Pokemod::setStartMap(const int startMap) throw(BoundsException) { - if (getMapIndex(s) == -1) - throw(BoundsException(className, "startMap")); - startMap = s; + if (mapIndex(startMap) == INT_MAX) + throw(BoundsException(className(), "startMap")); + m_startMap = startMap; } -void Pokemod::setStartWarp(const int s) throw(BoundsException) +void Pokemod::setStartWarp(const int startWarp) throw(BoundsException) { - if (getMapIndex(startMap) == -1) - throw(BoundsException(className, "startMap")); - if (getMapByID(startMap)->getWarpIndex(s) == -1) - throw(BoundsException(className, "startWarp")); - startWarp = s; + if (mapIndex(m_startMap) == INT_MAX) + throw(BoundsException(className(), "startMap")); + if (mapById(m_startMap)->warpIndex(startWarp) == INT_MAX) + throw(BoundsException(className(), "startWarp")); + m_startWarp = startWarp; } -void Pokemod::setWalkSkin(const QString& fname) throw(Exception) +void Pokemod::setWalkSkin(const QString& fileName) throw(Exception) { - QFile file(getWalkSkin()); + QFile file(walkSkin()); if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getWalkSkin())) - throw(SaveException(className, file.fileName())); + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, walkSkin())) + throw(SaveException(className(), file.fileName())); } -void Pokemod::setBikeSkin(const QString& fname) throw(Exception) +void Pokemod::setBikeSkin(const QString& fileName) throw(Exception) { - QFile file(getBikeSkin()); + QFile file(bikeSkin()); if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getBikeSkin())) - throw(SaveException(className, file.fileName())); + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, bikeSkin())) + throw(SaveException(className(), file.fileName())); } -void Pokemod::setSurfSkin(const QString& fname) throw(Exception) +void Pokemod::setSurfSkin(const QString& fileName) throw(Exception) { - QFile file(getSurfSkin()); + QFile file(surfSkin()); if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getSurfSkin())) - throw(SaveException(className, file.fileName())); + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, surfSkin())) + throw(SaveException(className(), file.fileName())); } -void Pokemod::setFlySkin(const QString& fname) throw(Exception) +void Pokemod::setFlySkin(const QString& fileName) throw(Exception) { - QFile file(getFlySkin()); + QFile file(flySkin()); if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getFlySkin())) - throw(SaveException(className, file.fileName())); + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, flySkin())) + throw(SaveException(className(), file.fileName())); } -void Pokemod::setFishSkin(const QString& fname) throw(Exception) +void Pokemod::setFishSkin(const QString& fileName) throw(Exception) { - QFile file(getFishSkin()); + QFile file(fishSkin()); if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getFishSkin())) - throw(SaveException(className, file.fileName())); + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, fishSkin())) + throw(SaveException(className(), file.fileName())); } -void Pokemod::setSurfFishSkin(const QString& fname) throw(Exception) +void Pokemod::setSurfFishSkin(const QString& fileName) throw(Exception) { - QFile file(getSurfFishSkin()); + QFile file(surfFishSkin()); if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getSurfFishSkin())) - throw(SaveException(className, file.fileName())); + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, surfFishSkin())) + throw(SaveException(className(), file.fileName())); } -void Pokemod::setSuperPCUname(const QString& u) +void Pokemod::setSuperPCUname(const QString& username) { - superPCUname = u; + m_superPCUname = username; } -void Pokemod::setSuperPCPasswd(const QString& p) +void Pokemod::setSuperPCPasswd(const QString& password) { - superPCPasswd = p; + m_superPCPasswd = password; } -void Pokemod::setTypeChart(const int att, const int def, const int n, const int d) throw(Exception) +void Pokemod::setTypeChart(const int attack, const int defense, const int numerator, const int denominator) throw(Exception) { - typeChart(att, def).set(n, d); + m_typeChart(attack, defense).set(numerator, denominator); } -void Pokemod::setTypeChartNum(const int att, const int def, const int n) throw(Exception) +void Pokemod::setRules(const Rules& rules) { - typeChart(att, def).setNum(n); + m_rules = rules; } -void Pokemod::setTypeChartDenom(const int att, const int def, const int d) throw(Exception) +void Pokemod::setRules(const QString& fileName) { - typeChart(att, def).setDenom(d); + m_rules.load(fileName); } -void Pokemod::setRules(const Rules& r) +QString Pokemod::title() const { - rules = r; + return m_title; } -void Pokemod::setRules(const QString& fname) +QString Pokemod::version() const { - rules.load(fname); + return m_version; } -QString Pokemod::getTitle() const +QString Pokemod::description() const { - return title; + return m_description; } -QString Pokemod::getVersion() const +int Pokemod::startMap() const { - return version; + return m_startMap; } -QString Pokemod::getDescription() const +int Pokemod::startWarp() const { - return description; + return m_startWarp; } -int Pokemod::getStartMap() const +QString Pokemod::walkSkin() const { - return startMap; + return QString("%1/image/skin/walk.png").arg(path()); } -int Pokemod::getStartWarp() const +QString Pokemod::bikeSkin() const { - return startWarp; + return QString("%1/image/skin/bike.png").arg(path()); } -QString Pokemod::getWalkSkin() const +QString Pokemod::surfSkin() const { - return QString("%1/image/skin/walk.png").arg(getPath()); + return QString("%1/image/skin/surf.png").arg(path()); } -QString Pokemod::getBikeSkin() const +QString Pokemod::flySkin() const { - return QString("%1/image/skin/bike.png").arg(getPath()); + return QString("%1/image/skin/fly.png").arg(path()); } -QString Pokemod::getSurfSkin() const +QString Pokemod::fishSkin() const { - return QString("%1/image/skin/surf.png").arg(getPath()); + return QString("%1/image/skin/fish.png").arg(path()); } -QString Pokemod::getFlySkin() const +QString Pokemod::surfFishSkin() const { - return QString("%1/image/skin/fly.png").arg(getPath()); + return QString("%1/image/skin/surfFish.png").arg(path()); } -QString Pokemod::getFishSkin() const +QString Pokemod::superPCUname() const { - return QString("%1/image/skin/fish.png").arg(getPath()); + return m_superPCUname; } -QString Pokemod::getSurfFishSkin() const +QString Pokemod::superPCPasswd() const { - return QString("%1/image/skin/surfFish.png").arg(getPath()); + return m_superPCPasswd; } -QString Pokemod::getSuperPCUname() const +const Matrix<Frac>* Pokemod::typeChart() const { - return superPCUname; + return &m_typeChart; } -QString Pokemod::getSuperPCPasswd() const +Matrix<Frac>* Pokemod::typeChart() { - return superPCPasswd; + return &m_typeChart; } -const Matrix<Frac>* Pokemod::getTypeChart() const +Frac Pokemod::typeChart(const int attack, const int defense) const { - return &typeChart; + return m_typeChart(attack, defense); } -Matrix<Frac>* Pokemod::getTypeChart() +const Rules* Pokemod::rules() const { - return &typeChart; + return &m_rules; } -Frac Pokemod::getTypeChart(const int att, const int def) const +Rules* Pokemod::rules() { - return typeChart(att, def); + return &m_rules; } -const Rules* Pokemod::getRules() const +const Ability* Pokemod::ability(const int index) const throw(IndexException) { - return &rules; + if (abilityCount() <= index) + throw(IndexException(className())); + return m_abilities.at(index); } -Rules* Pokemod::getRules() +Ability* Pokemod::ability(const int index) throw(IndexException) { - return &rules; + if (abilityCount() <= index) + throw(IndexException(className())); + return m_abilities[index]; } -const Ability* Pokemod::getAbility(const int i) const throw(IndexException) +const Ability* Pokemod::abilityById(const int id) const throw(IndexException) { - if (getAbilityCount() <= i) - throw(IndexException(className)); - return abilities.at(i); + return ability(abilityIndex(id)); } -Ability* Pokemod::getAbility(const int i) throw(IndexException) +Ability* Pokemod::abilityById(const int id) throw(IndexException) { - if (getAbilityCount() <= i) - throw(IndexException(className)); - return abilities[i]; + return ability(abilityIndex(id)); } -const Ability* Pokemod::getAbilityByID(const int i) const throw(IndexException) +int Pokemod::abilityIndex(const int id) const { - return getAbility(getAbilityIndex(i)); + for (int i = 0; i < abilityCount(); ++i) + { + if (m_abilities[i]->id() == id) + return i; + } + return INT_MAX; } -Ability* Pokemod::getAbilityByID(const int i) throw(IndexException) +int Pokemod::abilityCount() const { - return getAbility(getAbilityIndex(i)); + return m_abilities.size(); } -int Pokemod::getAbilityIndex(const int _id) const +Ability* Pokemod::newAbility() { - for (int i = 0; i < getAbilityCount(); ++i) - { - if (abilities[i]->getId() == _id) - return i; - } - return -1; + m_abilities.append(new Ability(this, newAbilityId())); + return m_abilities[abilityCount() - 1]; } -int Pokemod::getAbilityCount() const +Ability* Pokemod::newAbility(const QString& fileName) { - return abilities.size(); + m_abilities.append(new Ability(this, fileName, newAbilityId())); + return m_abilities[abilityCount() - 1]; } -Ability* Pokemod::newAbility() +Ability* Pokemod::newAbility(const Ability& ability) { - abilities.append(new Ability(this, getNewAbilityId())); - return abilities[getAbilityCount() - 1]; + m_abilities.append(new Ability(this, ability, newAbilityId())); + return m_abilities[abilityCount() - 1]; } -Ability* Pokemod::newAbility(const QString& fname) +void Pokemod::deleteAbility(const int index) throw(IndexException) { - abilities.append(new Ability(this, fname, getNewAbilityId())); - return abilities[getAbilityCount() - 1]; + if (abilityCount() <= index) + throw(IndexException(className())); + delete m_abilities[index]; + m_abilities.removeAt(index); } -Ability* Pokemod::newAbility(const Ability& a) +void Pokemod::deleteAbilityById(const int id) throw(IndexException) { - abilities.append(new Ability(this, a, getNewAbilityId())); - return abilities[getAbilityCount() - 1]; + deleteAbility(abilityIndex(id)); } -void Pokemod::deleteAbility(const int i) throw(IndexException) +int Pokemod::newAbilityId() const { - if (getAbilityCount() <= i) - throw(IndexException(className)); - delete abilities[i]; - abilities.removeAt(i); + int i = 0; + while ((i < abilityCount()) && (abilityIndex(i) != INT_MAX)) + ++i; + return i; } -const Author* Pokemod::getAuthor(const int i) const throw(IndexException) +const Author* Pokemod::author(const int index) const throw(IndexException) { - if (getAuthorCount() <= i) - throw(IndexException(className)); - return authors.at(i); + if (authorCount() <= index) + throw(IndexException(className())); + return m_authors.at(index); } -Author* Pokemod::getAuthor(const int i) throw(IndexException) +Author* Pokemod::author(const int index) throw(IndexException) { - if (getAuthorCount() <= i) - throw(IndexException(className)); - return authors[i]; + if (authorCount() <= index) + throw(IndexException(className())); + return m_authors[index]; } -const Author* Pokemod::getAuthorByID(const int i) const throw(IndexException) +const Author* Pokemod::authorById(const int id) const throw(IndexException) { - return getAuthor(getAuthorIndex(i)); + return author(authorIndex(id)); } -Author* Pokemod::getAuthorByID(const int i) throw(IndexException) +Author* Pokemod::authorById(const int id) throw(IndexException) { - return getAuthor(getAuthorIndex(i)); + return author(authorIndex(id)); } -int Pokemod::getAuthorIndex(const int _id) const +int Pokemod::authorIndex(const int id) const { - for (int i = 0; i < getAuthorCount(); ++i) + for (int i = 0; i < authorCount(); ++i) { - if (authors[i]->getId() == _id) + if (m_authors[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getAuthorCount() const +int Pokemod::authorCount() const { - return authors.size(); + return m_authors.size(); } Author* Pokemod::newAuthor() { - authors.append(new Author(this, getNewAuthorId())); - return authors[getAuthorCount() - 1]; + m_authors.append(new Author(this, newAuthorId())); + return m_authors[authorCount() - 1]; } -Author* Pokemod::newAuthor(const QString& fname) +Author* Pokemod::newAuthor(const QString& fileName) { - authors.append(new Author(this, fname, getNewAuthorId())); - return authors[getAuthorCount() - 1]; + m_authors.append(new Author(this, fileName, newAuthorId())); + return m_authors[authorCount() - 1]; } -Author* Pokemod::newAuthor(const Author& a) +Author* Pokemod::newAuthor(const Author& author) { - authors.append(new Author(this, a, getNewAuthorId())); - return authors[getAuthorCount() - 1]; + m_authors.append(new Author(this, author, newAuthorId())); + return m_authors[authorCount() - 1]; } -void Pokemod::deleteAuthor(const int i) throw(IndexException) +void Pokemod::deleteAuthor(const int index) throw(IndexException) { - if (getAuthorCount() <= i) - throw(IndexException(className)); - delete authors[i]; - authors.removeAt(i); + if (authorCount() <= index) + throw(IndexException(className())); + delete m_authors[index]; + m_authors.removeAt(index); } -const Badge* Pokemod::getBadge(const int i) const throw(IndexException) +void Pokemod::deleteAuthorById(const int id) throw(IndexException) { - if (i < getBadgeCount()) - throw(IndexException(className)); - return badges.at(i); + deleteAuthor(authorIndex(id)); } -Badge* Pokemod::getBadge(const int i) throw(IndexException) +int Pokemod::newAuthorId() const { - if (i < getBadgeCount()) - throw(IndexException(className)); - return badges[i]; + int i = 0; + while ((i < authorCount()) && (authorIndex(i) != INT_MAX)) + ++i; + return i; } -const Badge* Pokemod::getBadgeByID(const int i) const throw(IndexException) +const Badge* Pokemod::badge(const int index) const throw(IndexException) { - return getBadge(getBadgeIndex(i)); + if (badgeCount() <= index) + throw(IndexException(className())); + return m_badges.at(index); } -Badge* Pokemod::getBadgeByID(const int i) throw(IndexException) +Badge* Pokemod::badge(const int index) throw(IndexException) { - return getBadge(getBadgeIndex(i)); + if (badgeCount() <= index) + throw(IndexException(className())); + return m_badges[index]; } -int Pokemod::getBadgeIndex(const int _id) const +const Badge* Pokemod::badgeById(const int id) const throw(IndexException) { - for (int i = 0; i < getBadgeCount(); ++i) + return badge(badgeIndex(id)); +} + +Badge* Pokemod::badgeById(const int id) throw(IndexException) +{ + return badge(badgeIndex(id)); +} + +int Pokemod::badgeIndex(const int id) const +{ + for (int i = 0; i < badgeCount(); ++i) { - if (badges[i]->getId() == _id) + if (m_badges[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getBadgeCount() const +int Pokemod::badgeCount() const { - return badges.size(); + return m_badges.size(); } Badge* Pokemod::newBadge() { - badges.append(new Badge(this, getNewBadgeId())); - return badges[getBadgeCount() - 1]; + m_badges.append(new Badge(this, newBadgeId())); + return m_badges[badgeCount() - 1]; } -Badge* Pokemod::newBadge(const QString& fname) +Badge* Pokemod::newBadge(const QString& fileName) { - badges.append(new Badge(this, fname, getNewBadgeId())); - return badges[getBadgeCount() - 1]; + m_badges.append(new Badge(this, fileName, newBadgeId())); + return m_badges[badgeCount() - 1]; } -Badge* Pokemod::newBadge(const Badge& b) +Badge* Pokemod::newBadge(const Badge& badge) { - badges.append(new Badge(this, b, getNewBadgeId())); - return badges[getBadgeCount() - 1]; + m_badges.append(new Badge(this, badge, newBadgeId())); + return m_badges[badgeCount() - 1]; } -void Pokemod::deleteBadge(const int i) throw(IndexException) +void Pokemod::deleteBadge(const int index) throw(IndexException) { - if (getBadgeCount() <= i) - throw(IndexException(className)); - delete badges[i]; - badges.removeAt(i); + if (badgeCount() <= index) + throw(IndexException(className())); + delete m_badges[index]; + m_badges.removeAt(index); +} + +void Pokemod::deleteBadgeById(const int id) throw(IndexException) +{ + deleteBadge(badgeIndex(id)); +} + +int Pokemod::newBadgeId() const +{ + int i = 0; + while ((i < badgeCount()) && (badgeIndex(i) != INT_MAX)) + ++i; + return i; } -const CoinList* Pokemod::getCoinList(const int i) const throw(IndexException) +const CoinList* Pokemod::coinList(const int index) const throw(IndexException) { - if (getCoinListCount() <= i) - throw(IndexException(className)); - return coinLists.at(i); + if (coinListCount() <= index) + throw(IndexException(className())); + return m_coinLists.at(index); } -CoinList* Pokemod::getCoinList(const int i) throw(IndexException) +CoinList* Pokemod::coinList(const int index) throw(IndexException) { - if (getCoinListCount() <= i) - throw(IndexException(className)); - return coinLists[i]; + if (coinListCount() <= index) + throw(IndexException(className())); + return m_coinLists[index]; } -const CoinList* Pokemod::getCoinListByID(const int i) const throw(IndexException) +const CoinList* Pokemod::coinListById(const int id) const throw(IndexException) { - return getCoinList(getCoinListIndex(i)); + return coinList(coinListIndex(id)); } -CoinList* Pokemod::getCoinListByID(const int i) throw(IndexException) +CoinList* Pokemod::coinListById(const int id) throw(IndexException) { - return getCoinList(getCoinListIndex(i)); + return coinList(coinListIndex(id)); } -int Pokemod::getCoinListIndex(const int _id) const +int Pokemod::coinListIndex(const int id) const { - for (int i = 0; i < getCoinListCount(); ++i) + for (int i = 0; i < coinListCount(); ++i) { - if (coinLists[i]->getId() == _id) + if (m_coinLists[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getCoinListCount() const +int Pokemod::coinListCount() const { - return coinLists.size(); + return m_coinLists.size(); } CoinList* Pokemod::newCoinList() { - coinLists.append(new CoinList(this, getNewCoinListId())); - return coinLists[getCoinListCount() - 1]; + m_coinLists.append(new CoinList(this, newCoinListId())); + return m_coinLists[coinListCount() - 1]; } -CoinList* Pokemod::newCoinList(const QString& fname) +CoinList* Pokemod::newCoinList(const QString& fileName) { - coinLists.append(new CoinList(this, fname, getNewCoinListId())); - return coinLists[getCoinListCount() - 1]; + m_coinLists.append(new CoinList(this, fileName, newCoinListId())); + return m_coinLists[coinListCount() - 1]; } -CoinList* Pokemod::newCoinList(const CoinList& c) +CoinList* Pokemod::newCoinList(const CoinList& coinList) { - coinLists.append(new CoinList(this, c, getNewCoinListId())); - return coinLists[getCoinListCount() - 1]; + m_coinLists.append(new CoinList(this, coinList, newCoinListId())); + return m_coinLists[coinListCount() - 1]; } -void Pokemod::deleteCoinList(const int i) throw(IndexException) +void Pokemod::deleteCoinList(const int index) throw(IndexException) { - if (getCoinListCount() <= i) - throw(IndexException(className)); - delete coinLists[i]; - coinLists.removeAt(i); + if (coinListCount() <= index) + throw(IndexException(className())); + delete m_coinLists[index]; + m_coinLists.removeAt(index); } -const Dialog* Pokemod::getDialog(const int i) const throw(IndexException) +void Pokemod::deleteCoinListById(const int id) throw(IndexException) { - if (getDialogCount() <= i) - throw(IndexException(className)); - return dialogs.at(i); + deleteCoinList(coinListIndex(id)); } -Dialog* Pokemod::getDialog(const int i) throw(IndexException) +int Pokemod::newCoinListId() const { - if (getDialogCount() <= i) - throw(IndexException(className)); - return dialogs[i]; + int i = 0; + while ((i < coinListCount()) && (coinListIndex(i) != INT_MAX)) + ++i; + return i; +} + +const Dialog* Pokemod::dialog(const int index) const throw(IndexException) +{ + if (dialogCount() <= index) + throw(IndexException(className())); + return m_dialogs.at(index); +} + +Dialog* Pokemod::dialog(const int index) throw(IndexException) +{ + if (dialogCount() <= index) + throw(IndexException(className())); + return m_dialogs[index]; } -const Dialog* Pokemod::getDialogByID(const int i) const throw(IndexException) +const Dialog* Pokemod::dialogById(const int id) const throw(IndexException) { - return getDialog(getDialogIndex(i)); + return dialog(dialogIndex(id)); } -Dialog* Pokemod::getDialogByID(const int i) throw(IndexException) +Dialog* Pokemod::dialogById(const int id) throw(IndexException) { - return getDialog(getDialogIndex(i)); + return dialog(dialogIndex(id)); } -int Pokemod::getDialogIndex(const int _id) const +int Pokemod::dialogIndex(const int id) const { - for (int i = 0; i < getDialogCount(); ++i) + for (int i = 0; i < dialogCount(); ++i) { - if (dialogs[i]->getId() == _id) + if (m_dialogs[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getDialogCount() const +int Pokemod::dialogCount() const { - return dialogs.size(); + return m_dialogs.size(); } Dialog* Pokemod::newDialog() { - dialogs.append(new Dialog(this, getNewDialogId())); - return dialogs[getDialogCount() - 1]; + m_dialogs.append(new Dialog(this, newDialogId())); + return m_dialogs[dialogCount() - 1]; +} + +Dialog* Pokemod::newDialog(const QString& fileName) +{ + m_dialogs.append(new Dialog(this, fileName, newDialogId())); + return m_dialogs[dialogCount() - 1]; +} + +Dialog* Pokemod::newDialog(const Dialog& dialog) +{ + m_dialogs.append(new Dialog(this, dialog, newDialogId())); + return m_dialogs[dialogCount() - 1]; } -Dialog* Pokemod::newDialog(const QString& fname) +void Pokemod::deleteDialog(const int index) throw(IndexException) { - dialogs.append(new Dialog(this, fname, getNewDialogId())); - return dialogs[getDialogCount() - 1]; + if (dialogCount() <= index) + throw(IndexException(className())); + delete m_dialogs[index]; + m_dialogs.removeAt(index); } -Dialog* Pokemod::newDialog(const Dialog& d) +void Pokemod::deleteDialogById(const int id) throw(IndexException) { - dialogs.append(new Dialog(this, d, getNewDialogId())); - return dialogs[getDialogCount() - 1]; + deleteDialog(dialogIndex(id)); } -void Pokemod::deleteDialog(const int i) throw(IndexException) +int Pokemod::newDialogId() const { - if (getDialogCount() <= i) - throw(IndexException(className)); - delete dialogs[i]; - dialogs.removeAt(i); + int i = 0; + while ((i < dialogCount()) && (dialogIndex(i) != INT_MAX)) + ++i; + return i; } -const EggGroup* Pokemod::getEggGroup(const int i) const throw(IndexException) +const EggGroup* Pokemod::eggGroup(const int index) const throw(IndexException) { - if (getEggGroupCount() <= i) - throw(IndexException(className)); - return eggGroups.at(i); + if (eggGroupCount() <= index) + throw(IndexException(className())); + return m_eggGroups.at(index); } -EggGroup* Pokemod::getEggGroup(const int i) throw(IndexException) +EggGroup* Pokemod::eggGroup(const int index) throw(IndexException) { - if (getEggGroupCount() <= i) - throw(IndexException(className)); - return eggGroups[i]; + if (eggGroupCount() <= index) + throw(IndexException(className())); + return m_eggGroups[index]; } -const EggGroup* Pokemod::getEggGroupByID(const int i) const throw(IndexException) +const EggGroup* Pokemod::eggGroupById(const int id) const throw(IndexException) { - return getEggGroup(getEggGroupIndex(i)); + return eggGroup(eggGroupIndex(id)); } -EggGroup* Pokemod::getEggGroupByID(const int i) throw(IndexException) +EggGroup* Pokemod::eggGroupById(const int id) throw(IndexException) { - return getEggGroup(getEggGroupIndex(i)); + return eggGroup(eggGroupIndex(id)); } -int Pokemod::getEggGroupIndex(const int _id) const +int Pokemod::eggGroupIndex(const int id) const { - for (int i = 0; i < getEggGroupCount(); ++i) + for (int i = 0; i < eggGroupCount(); ++i) { - if (eggGroups[i]->getId() == _id) + if (m_eggGroups[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getEggGroupCount() const +int Pokemod::eggGroupCount() const { - return eggGroups.size(); + return m_eggGroups.size(); } EggGroup* Pokemod::newEggGroup() { - eggGroups.append(new EggGroup(this, getNewEggGroupId())); - return eggGroups[getEggGroupCount() - 1]; + m_eggGroups.append(new EggGroup(this, newEggGroupId())); + return m_eggGroups[eggGroupCount() - 1]; } -EggGroup* Pokemod::newEggGroup(const QString& fname) +EggGroup* Pokemod::newEggGroup(const QString& fileName) { - eggGroups.append(new EggGroup(this, fname, getNewEggGroupId())); - return eggGroups[getEggGroupCount() - 1]; + m_eggGroups.append(new EggGroup(this, fileName, newEggGroupId())); + return m_eggGroups[eggGroupCount() - 1]; } -EggGroup* Pokemod::newEggGroup(const EggGroup& e) +EggGroup* Pokemod::newEggGroup(const EggGroup& eggGroup) { - eggGroups.append(new EggGroup(this, e, getNewEggGroupId())); - return eggGroups[getEggGroupCount() - 1]; + m_eggGroups.append(new EggGroup(this, eggGroup, newEggGroupId())); + return m_eggGroups[eggGroupCount() - 1]; } -void Pokemod::deleteEggGroup(const int i) throw(IndexException) +void Pokemod::deleteEggGroup(const int index) throw(IndexException) { - if (getEggGroupCount() <= i) - throw(IndexException(className)); - delete eggGroups[i]; - eggGroups.removeAt(i); + if (eggGroupCount() <= index) + throw(IndexException(className())); + delete m_eggGroups[index]; + m_eggGroups.removeAt(index); } -const Item* Pokemod::getItem(const int i) const throw(IndexException) +void Pokemod::deleteEggGroupById(const int id) throw(IndexException) { - if (getItemCount() <= i) - throw(IndexException(className)); - return items.at(i); + deleteEggGroup(eggGroupIndex(id)); } -Item* Pokemod::getItem(const int i) throw(IndexException) +int Pokemod::newEggGroupId() const { - if (getItemCount() <= i) - throw(IndexException(className)); - return items[i]; + int i = 0; + while ((i < eggGroupCount()) && (eggGroupIndex(i) != INT_MAX)) + ++i; + return i; } -const Item* Pokemod::getItemByID(const int i) const throw(IndexException) +const Item* Pokemod::item(const int index) const throw(IndexException) { - return getItem(getItemIndex(i)); + if (itemCount() <= index) + throw(IndexException(className())); + return m_items.at(index); +} + +Item* Pokemod::item(const int index) throw(IndexException) +{ + if (itemCount() <= index) + throw(IndexException(className())); + return m_items[index]; +} + +const Item* Pokemod::itemById(const int id) const throw(IndexException) +{ + return item(itemIndex(id)); } -Item* Pokemod::getItemByID(const int i) throw(IndexException) +Item* Pokemod::itemById(const int id) throw(IndexException) { - return getItem(getItemIndex(i)); + return item(itemIndex(id)); } -int Pokemod::getItemIndex(const int _id) const +int Pokemod::itemIndex(const int id) const { - for (int i = 0; i < getItemCount(); ++i) + for (int i = 0; i < itemCount(); ++i) { - if (items[i]->getId() == _id) + if (m_items[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getItemCount() const +int Pokemod::itemCount() const { - return items.size(); + return m_items.size(); } Item* Pokemod::newItem() { - items.append(new Item(this, getNewItemId())); - return items[getItemCount() - 1]; + m_items.append(new Item(this, newItemId())); + return m_items[itemCount() - 1]; +} + +Item* Pokemod::newItem(const QString& fileName) +{ + m_items.append(new Item(this, fileName, newItemId())); + return m_items[itemCount() - 1]; } -Item* Pokemod::newItem(const QString& fname) +Item* Pokemod::newItem(const Item& item) { - items.append(new Item(this, fname, getNewItemId())); - return items[getItemCount() - 1]; + m_items.append(new Item(this, item, newItemId())); + return m_items[itemCount() - 1]; } -Item* Pokemod::newItem(const Item& i) +void Pokemod::deleteItem(const int index) throw(IndexException) { - items.append(new Item(this, i, getNewItemId())); - return items[getItemCount() - 1]; + if (itemCount() <= index) + throw(IndexException(className())); + delete m_items[index]; + m_items.removeAt(index); } -void Pokemod::deleteItem(const int i) throw(IndexException) +void Pokemod::deleteItemById(const int id) throw(IndexException) { - if (getItemCount() <= i) - throw(IndexException(className)); - delete items[i]; - items.removeAt(i); + deleteItem(itemIndex(id)); } -const ItemType* Pokemod::getItemType(const int i) const throw(IndexException) +int Pokemod::newItemId() const { - if (getItemTypeCount() <= i) - throw(IndexException(className)); - return itemTypes.at(i); + int i = 0; + for (; (i < itemCount()) && (itemIndex(i) != INT_MAX); ++i) + ; + return i; } -ItemType* Pokemod::getItemType(const int i) throw(IndexException) +const ItemType* Pokemod::itemType(const int index) const throw(IndexException) { - if (getItemTypeCount() <= i) - throw(IndexException(className)); - return itemTypes[i]; + if (itemTypeCount() <= index) + throw(IndexException(className())); + return m_itemTypes.at(index); } -const ItemType* Pokemod::getItemTypeByID(const int i) const throw(IndexException) +ItemType* Pokemod::itemType(const int index) throw(IndexException) { - return getItemType(getItemTypeIndex(i)); + if (itemTypeCount() <= index) + throw(IndexException(className())); + return m_itemTypes[index]; } -ItemType* Pokemod::getItemTypeByID(const int i) throw(IndexException) +const ItemType* Pokemod::itemTypeById(const int id) const throw(IndexException) { - return getItemType(getItemTypeIndex(i)); + return itemType(itemTypeIndex(id)); } -int Pokemod::getItemTypeIndex(const int _id) const +ItemType* Pokemod::itemTypeById(const int id) throw(IndexException) { - for (int i = 0; i < getItemTypeCount(); ++i) + return itemType(itemTypeIndex(id)); +} + +int Pokemod::itemTypeIndex(const int id) const +{ + for (int i = 0; i < itemTypeCount(); ++i) { - if (itemTypes[i]->getId() == _id) + if (m_itemTypes[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getItemTypeCount() const +int Pokemod::itemTypeCount() const { - return itemTypes.size(); + return m_itemTypes.size(); } ItemType* Pokemod::newItemType() { - itemTypes.append(new ItemType(this, getNewItemTypeId())); - return itemTypes[getItemTypeCount() - 1]; + m_itemTypes.append(new ItemType(this, newItemTypeId())); + return m_itemTypes[itemTypeCount() - 1]; +} + +ItemType* Pokemod::newItemType(const QString& fileName) +{ + m_itemTypes.append(new ItemType(this, fileName, newItemTypeId())); + return m_itemTypes[itemTypeCount() - 1]; } -ItemType* Pokemod::newItemType(const QString& fname) +ItemType* Pokemod::newItemType(const ItemType& itemType) { - itemTypes.append(new ItemType(this, fname, getNewItemTypeId())); - return itemTypes[getItemTypeCount() - 1]; + m_itemTypes.append(new ItemType(this, itemType, newItemTypeId())); + return m_itemTypes[itemTypeCount() - 1]; } -ItemType* Pokemod::newItemType(const ItemType& i) +void Pokemod::deleteItemType(const int index) throw(IndexException) { - itemTypes.append(new ItemType(this, i, getNewItemTypeId())); - return itemTypes[getItemTypeCount() - 1]; + if (itemTypeCount() <= index) + throw(IndexException(className())); + delete m_itemTypes[index]; + m_itemTypes.removeAt(index); } -void Pokemod::deleteItemType(const int i) throw(IndexException) +void Pokemod::deleteItemTypeById(const int id) throw(IndexException) { - if (getItemTypeCount() <= i) - throw(IndexException(className)); - delete itemTypes[i]; - itemTypes.removeAt(i); + deleteItemType(itemTypeIndex(id)); } -const Map* Pokemod::getMap(const int i) const throw(IndexException) +int Pokemod::newItemTypeId() const { - if (getMapCount() <= i) - throw(IndexException(className)); - return maps.at(i); + int i = 0; + while ((i < itemTypeCount()) && (itemTypeIndex(i) != INT_MAX)) + ++i; + return i; } -Map* Pokemod::getMap(const int i) throw(IndexException) +const Map* Pokemod::map(const int index) const throw(IndexException) { - if (getMapCount() <= i) - throw(IndexException(className)); - return maps[i]; + if (mapCount() <= index) + throw(IndexException(className())); + return m_maps.at(index); } -const Map* Pokemod::getMapByID(const int i) const throw(IndexException) +Map* Pokemod::map(const int index) throw(IndexException) { - return getMap(getMapIndex(i)); + if (mapCount() <= index) + throw(IndexException(className())); + return m_maps[index]; } -Map* Pokemod::getMapByID(const int i) throw(IndexException) +const Map* Pokemod::mapById(const int id) const throw(IndexException) { - return getMap(getMapIndex(i)); + return map(mapIndex(id)); } -int Pokemod::getMapIndex(const int _id) const +Map* Pokemod::mapById(const int id) throw(IndexException) { - for (int i = 0; i < getMapCount(); ++i) + return map(mapIndex(id)); +} + +int Pokemod::mapIndex(const int id) const +{ + for (int i = 0; i < mapCount(); ++i) { - if (maps[i]->getId() == _id) + if (m_maps[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getMapCount() const +int Pokemod::mapCount() const { - return maps.size(); + return m_maps.size(); } Map* Pokemod::newMap() { - maps.append(new Map(this, getNewMapId())); - return maps[getMapCount() - 1]; + m_maps.append(new Map(this, newMapId())); + return m_maps[mapCount() - 1]; } -Map* Pokemod::newMap(const QString& fname) +Map* Pokemod::newMap(const QString& fileName) { - maps.append(new Map(this, fname, getNewMapId())); - return maps[getMapCount() - 1]; + m_maps.append(new Map(this, fileName, newMapId())); + return m_maps[mapCount() - 1]; } -Map* Pokemod::newMap(const Map& m) +Map* Pokemod::newMap(const Map& map) { - maps.append(new Map(this, m, getNewMapId())); - return maps[getMapCount() - 1]; + m_maps.append(new Map(this, map, newMapId())); + return m_maps[mapCount() - 1]; } -void Pokemod::deleteMap(const int i) throw(IndexException) +void Pokemod::deleteMap(const int index) throw(IndexException) { - if (getMapCount() <= i) - throw(IndexException(className)); - delete maps[i]; - maps.removeAt(i); + if (mapCount() <= index) + throw(IndexException(className())); + delete m_maps[index]; + m_maps.removeAt(index); } -const Move* Pokemod::getMove(const int i) const throw(IndexException) +void Pokemod::deleteMapById(const int id) throw(IndexException) { - if (getMoveCount() <= i) - throw(IndexException(className)); - return moves.at(i); + deleteMap(mapIndex(id)); } -Move* Pokemod::getMove(const int i) throw(IndexException) +int Pokemod::newMapId() const { - if (getMoveCount() <= i) - throw(IndexException(className)); - return moves[i]; + int i = 0; + while ((i < mapCount()) && (mapIndex(i) != INT_MAX)) + ++i; + return i; } -const Move* Pokemod::getMoveByID(const int i) const throw(IndexException) +const Move* Pokemod::move(const int index) const throw(IndexException) { - return getMove(getMoveIndex(i)); + if (moveCount() <= index) + throw(IndexException(className())); + return m_moves.at(index); } -Move* Pokemod::getMoveByID(const int i) throw(IndexException) +Move* Pokemod::move(const int index) throw(IndexException) { - return getMove(getMoveIndex(i)); + if (moveCount() <= index) + throw(IndexException(className())); + return m_moves[index]; } -int Pokemod::getMoveIndex(const int _id) const +const Move* Pokemod::moveById(const int id) const throw(IndexException) { - for (int i = 0; i < getMoveCount(); ++i) + return move(moveIndex(id)); +} + +Move* Pokemod::moveById(const int id) throw(IndexException) +{ + return move(moveIndex(id)); +} + +int Pokemod::moveIndex(const int id) const +{ + for (int i = 0; i < moveCount(); ++i) { - if (moves[i]->getId() == _id) + if (m_moves[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getMoveCount() const +int Pokemod::moveCount() const { - return moves.size(); + return m_moves.size(); } Move* Pokemod::newMove() { - moves.append(new Move(this, getNewMoveId())); - return moves[getMoveCount() - 1]; + m_moves.append(new Move(this, newMoveId())); + return m_moves[moveCount() - 1]; } -Move* Pokemod::newMove(const QString& fname) +Move* Pokemod::newMove(const QString& fileName) { - moves.append(new Move(this, fname, getNewMoveId())); - return moves[getMoveCount() - 1]; + m_moves.append(new Move(this, fileName, newMoveId())); + return m_moves[moveCount() - 1]; } -Move* Pokemod::newMove(const Move& m) +Move* Pokemod::newMove(const Move& move) { - moves.append(new Move(this, m, getNewMoveId())); - return moves[getMoveCount() - 1]; + m_moves.append(new Move(this, move, newMoveId())); + return m_moves[moveCount() - 1]; } -void Pokemod::deleteMove(const int i) throw(IndexException) +void Pokemod::deleteMove(const int index) throw(IndexException) { - if (getMoveCount() <= i) - throw(IndexException(className)); - delete moves[i]; - moves.removeAt(i); + if (moveCount() <= index) + throw(IndexException(className())); + delete m_moves[index]; + m_moves.removeAt(index); } -const Nature* Pokemod::getNature(const int i) const throw(IndexException) +void Pokemod::deleteMoveById(const int id) throw(IndexException) { - if (getNatureCount() <= i) - throw(IndexException(className)); - return natures.at(i); + deleteMove(moveIndex(id)); } -Nature* Pokemod::getNature(const int i) throw(IndexException) +int Pokemod::newMoveId() const { - if (getNatureCount() <= i) - throw(IndexException(className)); - return natures[i]; + int i = 0; + while ((i < moveCount()) && (moveIndex(i) != INT_MAX)) + ++i; + return i; } -const Nature* Pokemod::getNatureByID(const int i) const throw(IndexException) +const Nature* Pokemod::nature(const int index) const throw(IndexException) { - return getNature(getNatureIndex(i)); + if (natureCount() <= index) + throw(IndexException(className())); + return m_natures.at(index); } -Nature* Pokemod::getNatureByID(const int i) throw(IndexException) +Nature* Pokemod::nature(const int index) throw(IndexException) { - return getNature(getNatureIndex(i)); + if (natureCount() <= index) + throw(IndexException(className())); + return m_natures[index]; } -int Pokemod::getNatureIndex(const int _id) const +const Nature* Pokemod::natureById(const int id) const throw(IndexException) { - for (int i = 0; i < getNatureCount(); ++i) + return nature(natureIndex(id)); +} + +Nature* Pokemod::natureById(const int id) throw(IndexException) +{ + return nature(natureIndex(id)); +} + +int Pokemod::natureIndex(const int id) const +{ + for (int i = 0; i < natureCount(); ++i) { - if (natures[i]->getId() == _id) + if (m_natures[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getNatureCount() const +int Pokemod::natureCount() const { - return natures.size(); + return m_natures.size(); } Nature* Pokemod::newNature() { - natures.append(new Nature(this, getNewNatureId())); - return natures[getNatureCount() - 1]; + m_natures.append(new Nature(this, newNatureId())); + return m_natures[natureCount() - 1]; +} + +Nature* Pokemod::newNature(const QString& fileName) +{ + m_natures.append(new Nature(this, fileName, newNatureId())); + return m_natures[natureCount() - 1]; +} + +Nature* Pokemod::newNature(const Nature& nature) +{ + m_natures.append(new Nature(this, nature, newNatureId())); + return m_natures[natureCount() - 1]; } -Nature* Pokemod::newNature(const QString& fname) +void Pokemod::deleteNature(const int index) throw(IndexException) { - natures.append(new Nature(this, fname, getNewNatureId())); - return natures[getNatureCount() - 1]; + if (natureCount() <= index) + throw(IndexException(className())); + delete m_natures[index]; + m_natures.removeAt(index); } -Nature* Pokemod::newNature(const Nature& n) +void Pokemod::deleteNatureById(const int id) throw(IndexException) { - natures.append(new Nature(this, n, getNewNatureId())); - return natures[getNatureCount() - 1]; + deleteNature(natureIndex(id)); } -void Pokemod::deleteNature(const int i) throw(IndexException) +int Pokemod::newNatureId() const { - if (getNatureCount() <= i) - throw(IndexException(className)); - delete natures[i]; - natures.removeAt(i); + int i = 0; + while ((i < natureCount()) && (natureIndex(i) != INT_MAX)) + ++i; + return i; } -const Species* Pokemod::getSpecies(const int i) const throw(IndexException) +const Species* Pokemod::species(const int index) const throw(IndexException) { - if (getSpeciesCount() <= i) - throw(IndexException(className)); - return species.at(i); + if (speciesCount() <= index) + throw(IndexException(className())); + return m_species.at(index); } -Species* Pokemod::getSpecies(const int i) throw(IndexException) +Species* Pokemod::species(const int index) throw(IndexException) { - if (getSpeciesCount() <= i) - throw(IndexException(className)); - return species[i]; + if (speciesCount() <= index) + throw(IndexException(className())); + return m_species[index]; } -const Species* Pokemod::getSpeciesByID(const int i) const throw(IndexException) +const Species* Pokemod::speciesById(const int id) const throw(IndexException) { - return getSpecies(getSpeciesIndex(i)); + return species(speciesIndex(id)); } -Species* Pokemod::getSpeciesByID(const int i) throw(IndexException) +Species* Pokemod::speciesById(const int id) throw(IndexException) { - return getSpecies(getSpeciesIndex(i)); + return species(speciesIndex(id)); } -int Pokemod::getSpeciesIndex(const int _id) const +int Pokemod::speciesIndex(const int id) const { - for (int i = 0; i < getSpeciesCount(); ++i) + for (int i = 0; i < speciesCount(); ++i) { - if (species[i]->getId() == _id) + if (m_species[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getSpeciesCount() const +int Pokemod::speciesCount() const { - return species.size(); + return m_species.size(); } Species* Pokemod::newSpecies() { - species.append(new Species(this, getNewSpeciesId())); - return species[getSpeciesCount() - 1]; + m_species.append(new Species(this, newSpeciesId())); + return m_species[speciesCount() - 1]; } -Species* Pokemod::newSpecies(const QString& fname) +Species* Pokemod::newSpecies(const QString& fileName) { - species.append(new Species(this, fname, getNewSpeciesId())); - return species[getSpeciesCount() - 1]; + m_species.append(new Species(this, fileName, newSpeciesId())); + return m_species[speciesCount() - 1]; } -Species* Pokemod::newSpecies(const Species& s) +Species* Pokemod::newSpecies(const Species& species) { - species.append(new Species(this, s, getNewSpeciesId())); - return species[getSpeciesCount() - 1]; + m_species.append(new Species(this, species, newSpeciesId())); + return m_species[speciesCount() - 1]; } -void Pokemod::deleteSpecies(const int i) throw(IndexException) +void Pokemod::deleteSpecies(const int index) throw(IndexException) { - if (getSpeciesCount() <= i) - throw(IndexException(className)); - delete species[i]; - species.removeAt(i); + if (speciesCount() <= index) + throw(IndexException(className())); + delete m_species[index]; + m_species.removeAt(index); } -const Store* Pokemod::getStore(const int i) const throw(IndexException) +void Pokemod::deleteSpeciesById(const int id) throw(IndexException) { - if (getStoreCount() <= i) - throw(IndexException(className)); - return stores.at(i); + deleteSpecies(speciesIndex(id)); +} + +int Pokemod::newSpeciesId() const +{ + int i = 0; + while ((i < speciesCount()) && (speciesIndex(i) != INT_MAX)) + ++i; + return i; } -Store* Pokemod::getStore(const int i) throw(IndexException) +const Store* Pokemod::store(const int index) const throw(IndexException) { - if (getStoreCount() <= i) - throw(IndexException(className)); - return stores[i]; + if (storeCount() <= index) + throw(IndexException(className())); + return m_stores.at(index); } -const Store* Pokemod::getStoreByID(const int i) const throw(IndexException) +Store* Pokemod::store(const int index) throw(IndexException) { - return getStore(getStoreIndex(i)); + if (storeCount() <= index) + throw(IndexException(className())); + return m_stores[index]; } -Store* Pokemod::getStoreByID(const int i) throw(IndexException) +const Store* Pokemod::storeById(const int id) const throw(IndexException) { - return getStore(getStoreIndex(i)); + return store(storeIndex(id)); } -int Pokemod::getStoreIndex(const int _id) const +Store* Pokemod::storeById(const int id) throw(IndexException) { - for (int i = 0; i < getStoreCount(); ++i) + return store(storeIndex(id)); +} + +int Pokemod::storeIndex(const int id) const +{ + for (int i = 0; i < storeCount(); ++i) { - if (stores[i]->getId() == _id) + if (m_stores[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getStoreCount() const +int Pokemod::storeCount() const { - return stores.size(); + return m_stores.size(); } Store* Pokemod::newStore() { - stores.append(new Store(this, getNewStoreId())); - return stores[getStoreCount() - 1]; + m_stores.append(new Store(this, newStoreId())); + return m_stores[storeCount() - 1]; +} + +Store* Pokemod::newStore(const QString& fileName) +{ + m_stores.append(new Store(this, fileName, newStoreId())); + return m_stores[storeCount() - 1]; } -Store* Pokemod::newStore(const QString& fname) +Store* Pokemod::newStore(const Store& store) { - stores.append(new Store(this, fname, getNewStoreId())); - return stores[getStoreCount() - 1]; + m_stores.append(new Store(this, store, newStoreId())); + return m_stores[storeCount() - 1]; } -Store* Pokemod::newStore(const Store& s) +void Pokemod::deleteStore(const int index) throw(IndexException) { - stores.append(new Store(this, s, getNewStoreId())); - return stores[getStoreCount() - 1]; + if (storeCount() <= index) + throw(IndexException(className())); + delete m_stores[index]; + m_stores.removeAt(index); } -void Pokemod::deleteStore(const int i) throw(IndexException) +void Pokemod::deleteStoreById(const int id) throw(IndexException) { - if (getStoreCount() <= i) - throw(IndexException(className)); - delete stores[i]; - stores.removeAt(i); + deleteStore(storeIndex(id)); } -const Tile* Pokemod::getTile(const int i) const throw(IndexException) +int Pokemod::newStoreId() const { - if (getTileCount() <= i) - throw(IndexException(className)); - return tiles.at(i); + int i = 0; + while ((i < storeCount()) && (storeIndex(i) != INT_MAX)) + ++i; + return i; } -Tile* Pokemod::getTile(const int i) throw(IndexException) +const Tile* Pokemod::tile(const int index) const throw(IndexException) { - if (getTileCount() <= i) - throw(IndexException(className)); - return tiles[i]; + if (tileCount() <= index) + throw(IndexException(className())); + return m_tiles.at(index); } -const Tile* Pokemod::getTileByID(const int i) const throw(IndexException) +Tile* Pokemod::tile(const int index) throw(IndexException) { - return getTile(getTileIndex(i)); + if (tileCount() <= index) + throw(IndexException(className())); + return m_tiles[index]; } -Tile* Pokemod::getTileByID(const int i) throw(IndexException) +const Tile* Pokemod::tileById(const int id) const throw(IndexException) { - return getTile(getTileIndex(i)); + return tile(tileIndex(id)); } -int Pokemod::getTileIndex(const int _id) const +Tile* Pokemod::tileById(const int id) throw(IndexException) { - for (int i = 0; i < getTileCount(); ++i) + return tile(tileIndex(id)); +} + +int Pokemod::tileIndex(const int id) const +{ + for (int i = 0; i < tileCount(); ++i) { - if (tiles[i]->getId() == _id) + if (m_tiles[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getTileCount() const +int Pokemod::tileCount() const { - return tiles.size(); + return m_tiles.size(); } Tile* Pokemod::newTile() { - tiles.append(new Tile(this, getNewTileId())); - return tiles[getTileCount() - 1]; + m_tiles.append(new Tile(this, newTileId())); + return m_tiles[tileCount() - 1]; } -Tile* Pokemod::newTile(const QString& fname) +Tile* Pokemod::newTile(const QString& fileName) { - tiles.append(new Tile(this, fname, getNewTileId())); - return tiles[getTileCount() - 1]; + m_tiles.append(new Tile(this, fileName, newTileId())); + return m_tiles[tileCount() - 1]; } -Tile* Pokemod::newTile(const Tile& t) +Tile* Pokemod::newTile(const Tile& tile) { - tiles.append(new Tile(this, t, getNewTileId())); - return tiles[getTileCount() - 1]; + m_tiles.append(new Tile(this, tile, newTileId())); + return m_tiles[tileCount() - 1]; } -void Pokemod::deleteTile(const int i) throw(IndexException) +void Pokemod::deleteTile(const int index) throw(IndexException) { - if (getTileCount() <= i) - throw(IndexException(className)); - delete tiles[i]; - tiles.removeAt(i); + if (tileCount() <= index) + throw(IndexException(className())); + delete m_tiles[index]; + m_tiles.removeAt(index); +} + +void Pokemod::deleteTileById(const int id) throw(IndexException) +{ + deleteTile(tileIndex(id)); +} + +int Pokemod::newTileId() const +{ + int i = 0; + while ((i < tileCount()) && (tileIndex(i) != INT_MAX)) + ++i; + return i; } -const Time* Pokemod::getTime(const int i) const throw(IndexException) +const Time* Pokemod::time(const int index) const throw(IndexException) { - if (getTimeCount() <= i) - throw(IndexException(className)); - return times.at(i); + if (timeCount() <= index) + throw(IndexException(className())); + return m_times.at(index); } -Time* Pokemod::getTime(const int i) throw(IndexException) +Time* Pokemod::time(const int i) throw(IndexException) { - if (getTimeCount() <= i) - throw(IndexException(className)); - return times[i]; + if (timeCount() <= i) + throw(IndexException(className())); + return m_times[i]; } -const Time* Pokemod::getTimeByID(const int i) const throw(IndexException) +const Time* Pokemod::timeById(const int id) const throw(IndexException) { - return getTime(getTimeIndex(i)); + return time(timeIndex(id)); } -Time* Pokemod::getTimeByID(const int i) throw(IndexException) +Time* Pokemod::timeById(const int id) throw(IndexException) { - return getTime(getTimeIndex(i)); + return time(timeIndex(id)); } -int Pokemod::getTimeIndex(const int _id) const +int Pokemod::timeIndex(const int id) const { - for (int i = 0; i < getTimeCount(); ++i) + for (int i = 0; i < timeCount(); ++i) { - if (times[i]->getId() == _id) + if (m_times[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getTimeCount() const +int Pokemod::timeCount() const { - return times.size(); + return m_times.size(); } Time* Pokemod::newTime() { - times.append(new Time(this, getNewTimeId())); - return times[getTimeCount() - 1]; + m_times.append(new Time(this, newTimeId())); + return m_times[timeCount() - 1]; } -Time* Pokemod::newTime(const QString& fname) +Time* Pokemod::newTime(const QString& fileName) { - times.append(new Time(this, fname, getNewTimeId())); - return times[getTimeCount() - 1]; + m_times.append(new Time(this, fileName, newTimeId())); + return m_times[timeCount() - 1]; } -Time* Pokemod::newTime(const Time& t) +Time* Pokemod::newTime(const Time& time) { - times.append(new Time(this, t, getNewTimeId())); - return times[getTimeCount() - 1]; + m_times.append(new Time(this, time, newTimeId())); + return m_times[timeCount() - 1]; } -void Pokemod::deleteTime(const int i) throw(IndexException) +void Pokemod::deleteTime(const int index) throw(IndexException) { - if (getTimeCount() <= i) - throw(IndexException(className)); - delete times[i]; - times.removeAt(i); + if (timeCount() <= index) + throw(IndexException(className())); + delete m_times[index]; + m_times.removeAt(index); } -const Trainer* Pokemod::getTrainer(const int i) const throw(IndexException) +void Pokemod::deleteTimeById(const int id) throw(IndexException) { - if (getTrainerCount() <= i) - throw(IndexException(className)); - return trainers.at(i); + deleteTime(timeIndex(id)); } -Trainer* Pokemod::getTrainer(const int i) throw(IndexException) +int Pokemod::newTimeId() const { - if (getTrainerCount() <= i) - throw(IndexException(className)); - return trainers[i]; + int i = 0; + while ((i < timeCount()) && (timeIndex(i) != INT_MAX)) + ++i; + return i; } -const Trainer* Pokemod::getTrainerByID(const int i) const throw(IndexException) +const Trainer* Pokemod::trainer(const int index) const throw(IndexException) { - return getTrainer(getTrainerIndex(i)); + if (trainerCount() <= index) + throw(IndexException(className())); + return m_trainers.at(index); } -Trainer* Pokemod::getTrainerByID(const int i) throw(IndexException) +Trainer* Pokemod::trainer(const int index) throw(IndexException) { - return getTrainer(getTrainerIndex(i)); + if (trainerCount() <= index) + throw(IndexException(className())); + return m_trainers[index]; } -int Pokemod::getTrainerIndex(const int _id) const +const Trainer* Pokemod::trainerById(const int id) const throw(IndexException) { - for (int i = 0; i < getTrainerCount(); ++i) + return trainer(trainerIndex(id)); +} + +Trainer* Pokemod::trainerById(const int id) throw(IndexException) +{ + return trainer(trainerIndex(id)); +} + +int Pokemod::trainerIndex(const int id) const +{ + for (int i = 0; i < trainerCount(); ++i) { - if (trainers[i]->getId() == _id) + if (m_trainers[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getTrainerCount() const +int Pokemod::trainerCount() const { - return trainers.size(); + return m_trainers.size(); } Trainer* Pokemod::newTrainer() { - trainers.append(new Trainer(this, getNewTrainerId())); - return trainers[getTrainerCount() - 1]; + m_trainers.append(new Trainer(this, newTrainerId())); + return m_trainers[trainerCount() - 1]; +} + +Trainer* Pokemod::newTrainer(const QString& fileName) +{ + m_trainers.append(new Trainer(this, fileName, newTrainerId())); + return m_trainers[trainerCount() - 1]; } -Trainer* Pokemod::newTrainer(const QString& fname) +Trainer* Pokemod::newTrainer(const Trainer& trainer) { - trainers.append(new Trainer(this, fname, getNewTrainerId())); - return trainers[getTrainerCount() - 1]; + m_trainers.append(new Trainer(this, trainer, newTrainerId())); + return m_trainers[trainerCount() - 1]; } -Trainer* Pokemod::newTrainer(const Trainer& t) +void Pokemod::deleteTrainer(const int index) throw(IndexException) { - trainers.append(new Trainer(this, t, getNewTrainerId())); - return trainers[getTrainerCount() - 1]; + if (trainerCount() <= index) + throw(IndexException(className())); + delete m_trainers[index]; + m_trainers.removeAt(index); } -void Pokemod::deleteTrainer(const int i) throw(IndexException) +void Pokemod::deleteTrainerById(const int id) throw(IndexException) { - if (getTrainerCount() <= i) - throw(IndexException(className)); - delete trainers[i]; - trainers.removeAt(i); + deleteTrainer(trainerIndex(id)); } -const Type* Pokemod::getType(const int i) const throw(IndexException) +int Pokemod::newTrainerId() const { - if (getTypeCount() <= i) - throw(IndexException(className)); - return types.at(i); + int i = 0; + while ((i < trainerCount()) && (trainerIndex(i) != INT_MAX)) + ++i; + return i; } -Type* Pokemod::getType(const int i) throw(IndexException) +const Type* Pokemod::type(const int index) const throw(IndexException) { - if (getTypeCount() <= i) - throw(IndexException(className)); - return types[i]; + if (typeCount() <= index) + throw(IndexException(className())); + return m_types.at(index); } -const Type* Pokemod::getTypeByID(const int i) const throw(IndexException) +Type* Pokemod::type(const int index) throw(IndexException) { - return getType(getTypeIndex(i)); + if (typeCount() <= index) + throw(IndexException(className())); + return m_types[index]; } -Type* Pokemod::getTypeByID(const int i) throw(IndexException) +const Type* Pokemod::typeById(const int id) const throw(IndexException) { - return getType(getTypeIndex(i)); + return type(typeIndex(id)); } -int Pokemod::getTypeIndex(const int _id) const +Type* Pokemod::typeById(const int id) throw(IndexException) { - for (int i = 0; i < getTypeCount(); ++i) + return type(typeIndex(id)); +} + +int Pokemod::typeIndex(const int id) const +{ + for (int i = 0; i < typeCount(); ++i) { - if (types[i]->getId() == _id) + if (m_types[i]->id() == id) return i; } - return -1; + return INT_MAX; } -int Pokemod::getTypeCount() const +int Pokemod::typeCount() const { - return types.size(); + return m_types.size(); } Type* Pokemod::newType() { int i; - types.append(new Type(this, i = getNewTypeId())); - typeChart.addCol(Frac(1, 1)); - typeChart.addRow(Frac(1, 1)); - return types[getTypeCount() - 1]; + m_types.append(new Type(this, i = newTypeId())); + m_typeChart.addColumn(Frac(1, 1)); + m_typeChart.addRow(Frac(1, 1)); + return m_types[typeCount() - 1]; } -Type* Pokemod::newType(const QString& fname) +Type* Pokemod::newType(const QString& fileName) { int i; - types.append(new Type(this, fname, i = getNewTypeId())); - typeChart.addCol(Frac(1, 1)); - typeChart.addRow(Frac(1, 1)); - return types[getTypeCount() - 1]; + m_types.append(new Type(this, fileName, i = newTypeId())); + m_typeChart.addColumn(Frac(1, 1)); + m_typeChart.addRow(Frac(1, 1)); + return m_types[typeCount() - 1]; } -Type* Pokemod::newType(const Type& t) +Type* Pokemod::newType(const Type& type) { - int i; - types.append(new Type(this, t, i = getNewTypeId())); - typeChart.addCol(Frac(1, 1)); - typeChart.addRow(Frac(1, 1)); - return types[getTypeCount() - 1]; + m_types.append(new Type(this, type, newTypeId())); + m_typeChart.addColumn(Frac(1, 1)); + m_typeChart.addRow(Frac(1, 1)); + return m_types[typeCount() - 1]; +} + +void Pokemod::deleteType(const int index) throw(IndexException) +{ + if (typeCount() <= index) + throw(IndexException(className())); + delete m_types[index]; + m_typeChart.deleteColumn(index); + m_typeChart.deleteRow(index); + m_types.removeAt(index); +} + +void Pokemod::deleteTypeById(const int id) throw(IndexException) +{ + deleteType(typeIndex(id)); } -void Pokemod::deleteType(const int i) throw(IndexException) +int Pokemod::newTypeId() const { - if (getTypeCount() <= i) - throw(IndexException(className)); - delete types[i]; - typeChart.deleteCol(i); - typeChart.deleteRow(i); - types.removeAt(i); + int i = 0; + while ((i < typeCount()) && (typeIndex(i) != INT_MAX)) + ++i; + return i; } Pokemod& Pokemod::operator=(const Pokemod& rhs) { if (this == &rhs) return *this; - title = rhs.title; - version = rhs.version; - description = rhs.description; - startMap = rhs.startMap; - startWarp = rhs.startWarp; - superPCUname = rhs.superPCUname; - superPCPasswd = rhs.superPCPasswd; - typeChart = rhs.typeChart; - rules = rhs.rules; - abilities.clear(); - for (int i = 0; i < rhs.getAbilityCount(); ++i) - abilities.append(new Ability(this, *rhs.getAbility(i), rhs.getAbility(i)->getId())); - authors.clear(); - for (int i = 0; i < rhs.getAuthorCount(); ++i) - authors.append(new Author(this, *rhs.getAuthor(i), rhs.getAuthor(i)->getId())); - badges.clear(); - for (int i = 0; i < rhs.getBadgeCount(); ++i) - badges.append(new Badge(this, *rhs.getBadge(i), rhs.getBadge(i)->getId())); - coinLists.clear(); - for (int i = 0; i < rhs.getCoinListCount(); ++i) - coinLists.append(new CoinList(this, *rhs.getCoinList(i), rhs.getCoinList(i)->getId())); - dialogs.clear(); - for (int i = 0; i < rhs.getDialogCount(); ++i) - dialogs.append(new Dialog(this, *rhs.getDialog(i), rhs.getDialog(i)->getId())); - eggGroups.clear(); - for (int i = 0; i < rhs.getEggGroupCount(); ++i) - eggGroups.append(new EggGroup(this, *rhs.getEggGroup(i), rhs.getEggGroup(i)->getId())); - items.clear(); - for (int i = 0; i < rhs.getItemCount(); ++i) - items.append(new Item(this, *rhs.getItem(i), rhs.getItem(i)->getId())); - itemTypes.clear(); - for (int i = 0; i < rhs.getItemTypeCount(); ++i) - itemTypes.append(new ItemType(this, *rhs.getItemType(i), rhs.getItemType(i)->getId())); - maps.clear(); - for (int i = 0; i < rhs.getMapCount(); ++i) - maps.append(new Map(this, *rhs.getMap(i), rhs.getMap(i)->getId())); - moves.clear(); - for (int i = 0; i < rhs.getMoveCount(); ++i) - moves.append(new Move(this, *rhs.getMove(i), rhs.getMove(i)->getId())); - natures.clear(); - for (int i = 0; i < rhs.getNatureCount(); ++i) - natures.append(new Nature(this, *rhs.getNature(i), rhs.getNature(i)->getId())); - species.clear(); - for (int i = 0; i < rhs.getSpeciesCount(); ++i) - species.append(new Species(this, *rhs.getSpecies(i), rhs.getSpecies(i)->getId())); - stores.clear(); - for (int i = 0; i < rhs.getStoreCount(); ++i) - stores.append(new Store(this, *rhs.getStore(i), rhs.getStore(i)->getId())); - tiles.clear(); - for (int i = 0; i < rhs.getTileCount(); ++i) - tiles.append(new Tile(this, *rhs.getTile(i), rhs.getTile(i)->getId())); - trainers.clear(); - for (int i = 0; i < rhs.getTrainerCount(); ++i) - trainers.append(new Trainer(this, *rhs.getTrainer(i), rhs.getTrainer(i)->getId())); - types.clear(); - for (int i = 0; i < rhs.getTimeCount(); ++i) - times.append(new Time(this, *rhs.getTime(i), rhs.getTime(i)->getId())); - types.clear(); - for (int i = 0; i < rhs.getTypeCount(); ++i) - types.append(new Type(this, *rhs.getType(i), rhs.getType(i)->getId())); + m_title = rhs.m_title; + m_version = rhs.m_version; + m_description = rhs.m_description; + m_startMap = rhs.m_startMap; + m_startWarp = rhs.m_startWarp; + m_superPCUname = rhs.m_superPCUname; + m_superPCPasswd = rhs.m_superPCPasswd; + m_typeChart = rhs.m_typeChart; + m_rules = rhs.m_rules; + m_abilities.clear(); + foreach (Ability* ability, rhs.m_abilities) + m_abilities.append(new Ability(this, *ability, ability->id())); + m_authors.clear(); + foreach (Author* author, rhs.m_authors) + m_authors.append(new Author(this, *author, author->id())); + m_badges.clear(); + foreach (Badge* badge, rhs.m_badges) + m_badges.append(new Badge(this, *badge, badge->id())); + m_coinLists.clear(); + foreach (CoinList* coinList, rhs.m_coinLists) + m_coinLists.append(new CoinList(this, *coinList, coinList->id())); + m_dialogs.clear(); + foreach (Dialog* dialog, rhs.m_dialogs) + m_dialogs.append(new Dialog(this, *dialog, dialog->id())); + m_eggGroups.clear(); + foreach (EggGroup* eggGroup, rhs.m_eggGroups) + m_eggGroups.append(new EggGroup(this, *eggGroup, eggGroup->id())); + m_items.clear(); + foreach (Item* item, rhs.m_items) + m_items.append(new Item(this, *item, item->id())); + m_itemTypes.clear(); + foreach (ItemType* itemType, rhs.m_itemTypes) + m_itemTypes.append(new ItemType(this, *itemType, itemType->id())); + m_maps.clear(); + foreach (Map* map, rhs.m_maps) + m_maps.append(new Map(this, *map, map->id())); + m_species.clear(); + foreach (Species* species, rhs.m_species) + m_species.append(new Species(this, *species, species->id())); + m_stores.clear(); + foreach (Store* store, rhs.m_stores) + m_stores.append(new Store(this, *store, store->id())); + m_tiles.clear(); + foreach (Tile* tile, rhs.m_tiles) + m_tiles.append(new Tile(this, *tile, tile->id())); + m_times.clear(); + foreach (Time* time, rhs.m_times) + m_times.append(new Time(this, *time, time->id())); + m_trainers.clear(); + foreach (Trainer* trainer, rhs.m_trainers) + m_trainers.append(new Trainer(this, *trainer, trainer->id())); + m_types.clear(); + foreach (Type* type, rhs.m_types) + m_types.append(new Type(this, *type, type->id())); return *this; } diff --git a/pokemod/Pokemod.h b/pokemod/Pokemod.h index 39d73359..84b885df 100644 --- a/pokemod/Pokemod.h +++ b/pokemod/Pokemod.h @@ -1,40 +1,39 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Pokemod.h -// Purpose: Define a custom PokéMod for PokéGen -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sat Feb 24 21:41:19 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> #include <Matrix.h> #include <Point.h> +// Pokemod includes #include "Object.h" #include "Rules.h" +// Forward declarations class Ability; class Author; class Badge; @@ -162,301 +161,316 @@ class Pokemod : public Object static const QStringList HMStr; Pokemod(); - Pokemod(const Pokemod& p); - Pokemod(const QString& fpath); + Pokemod(const Pokemod& pokemod); + Pokemod(const QString& filePath); ~Pokemod(); void load(const QString& fpath, const int = 0) throw(Exception); void save() const throw(Exception); - QString getPath() const; - void setPath(const QString& p); + QString path() const; + void setPath(const QString& path); - int maxCompatability(const Pokemod& p) const; + int maxCompatability(const Pokemod& rhs) const; void validationMsg(const QString& msg, Validation val = V_Error) const throw(Exception); void setValOutput(QStringList& s); void unsetValOutput(); - void setTitle(const QString& t); - void setVersion(const QString& v); - void setDescription(const QString& d); - void setStartMap(const int s) throw(BoundsException); - void setStartWarp(const int s) throw(BoundsException); - void setWalkSkin(const QString& fname) throw(Exception); - void setBikeSkin(const QString& fname) throw(Exception); - void setSurfSkin(const QString& fname) throw(Exception); - void setFlySkin(const QString& fname) throw(Exception); - void setFishSkin(const QString& fname) throw(Exception); - void setSurfFishSkin(const QString& fname) throw(Exception); - void setSuperPCUname(const QString& u); - void setSuperPCPasswd(const QString& p); - void setTypeChart(const int att, const int def, const int n, const int d) throw(Exception); - void setTypeChartNum(const int att, const int def, const int n) throw(Exception); - void setTypeChartDenom(const int att, const int def, const int d) throw(Exception); - void setRules(const Rules& r); - void setRules(const QString& fname); + void setTitle(const QString& title); + void setVersion(const QString& version); + void setDescription(const QString& description); + void setStartMap(const int startMap) throw(BoundsException); + void setStartWarp(const int startWarp) throw(BoundsException); + void setWalkSkin(const QString& fileName) throw(Exception); + void setBikeSkin(const QString& fileName) throw(Exception); + void setSurfSkin(const QString& fileName) throw(Exception); + void setFlySkin(const QString& fileName) throw(Exception); + void setFishSkin(const QString& fileName) throw(Exception); + void setSurfFishSkin(const QString& fileName) throw(Exception); + void setSuperPCUname(const QString& username); + void setSuperPCPasswd(const QString& password); + void setTypeChart(const int attack, const int defense, const int numerator, const int denominator) throw(Exception); + void setRules(const Rules& rules); + void setRules(const QString& fileName); - QString getTitle() const; - QString getVersion() const; - QString getDescription() const; - int getStartMap() const; - int getStartWarp() const; - QString getWalkSkin() const; - QString getBikeSkin() const; - QString getSurfSkin() const; - QString getFlySkin() const; - QString getFishSkin() const; - QString getSurfFishSkin() const; - QString getSuperPCUname() const; - QString getSuperPCPasswd() const; - const Matrix<Frac>* getTypeChart() const; - Matrix<Frac>* getTypeChart(); - Frac getTypeChart(const int att, const int def) const; - const Rules* getRules() const; - Rules* getRules(); + QString title() const; + QString version() const; + QString description() const; + int startMap() const; + int startWarp() const; + QString walkSkin() const; + QString bikeSkin() const; + QString surfSkin() const; + QString flySkin() const; + QString fishSkin() const; + QString surfFishSkin() const; + QString superPCUname() const; + QString superPCPasswd() const; + const Matrix<Frac>* typeChart() const; + Matrix<Frac>* typeChart(); + Frac typeChart(const int attack, const int defense) const; + const Rules* rules() const; + Rules* rules(); - const Ability* getAbility(const int i) const throw(IndexException); - Ability* getAbility(const int i) throw(IndexException); - const Ability* getAbilityByID(const int i) const throw(IndexException); - Ability* getAbilityByID(const int i) throw(IndexException); - int getAbilityIndex(const int i) const; - int getAbilityCount() const; + const Ability* ability(const int index) const throw(IndexException); + Ability* ability(const int index) throw(IndexException); + const Ability* abilityById(const int id) const throw(IndexException); + Ability* abilityById(const int id) throw(IndexException); + int abilityIndex(const int id) const; + int abilityCount() const; Ability* newAbility(); - Ability* newAbility(const QString& fname); - Ability* newAbility(const Ability& a); - void deleteAbility(const int i) throw(IndexException); + Ability* newAbility(const QString& fileName); + Ability* newAbility(const Ability& ability); + void deleteAbility(const int index) throw(IndexException); + void deleteAbilityById(const int id) throw(IndexException); - const Author* getAuthor(const int i) const throw(IndexException); - Author* getAuthor(const int i) throw(IndexException); - const Author* getAuthorByID(const int i) const throw(IndexException); - Author* getAuthorByID(const int i) throw(IndexException); - int getAuthorIndex(const int i) const; - int getAuthorCount() const; + const Author* author(const int index) const throw(IndexException); + Author* author(const int index) throw(IndexException); + const Author* authorById(const int id) const throw(IndexException); + Author* authorById(const int id) throw(IndexException); + int authorIndex(const int id) const; + int authorCount() const; Author* newAuthor(); - Author* newAuthor(const QString& fname); - Author* newAuthor(const Author& a); - void deleteAuthor(const int i) throw(IndexException); + Author* newAuthor(const QString& fileName); + Author* newAuthor(const Author& author); + void deleteAuthor(const int index) throw(IndexException); + void deleteAuthorById(const int id) throw(IndexException); - const Badge* getBadge(const int i) const throw(IndexException); - Badge* getBadge(const int i) throw(IndexException); - const Badge* getBadgeByID(const int i) const throw(IndexException); - Badge* getBadgeByID(const int i) throw(IndexException); - int getBadgeIndex(const int i) const; - int getBadgeCount() const; + const Badge* badge(const int index) const throw(IndexException); + Badge* badge(const int index) throw(IndexException); + const Badge* badgeById(const int id) const throw(IndexException); + Badge* badgeById(const int id) throw(IndexException); + int badgeIndex(const int id) const; + int badgeCount() const; Badge* newBadge(); - Badge* newBadge(const QString& fname); - Badge* newBadge(const Badge& b); - void deleteBadge(const int i) throw(IndexException); + Badge* newBadge(const QString& fileName); + Badge* newBadge(const Badge& badge); + void deleteBadge(const int index) throw(IndexException); + void deleteBadgeById(const int id) throw(IndexException); - const CoinList* getCoinList(const int i) const throw(IndexException); - CoinList* getCoinList(const int i) throw(IndexException); - const CoinList* getCoinListByID(const int i) const throw(IndexException); - CoinList* getCoinListByID(const int i) throw(IndexException); - int getCoinListIndex(const int i) const; - int getCoinListCount() const; + const CoinList* coinList(const int index) const throw(IndexException); + CoinList* coinList(const int index) throw(IndexException); + const CoinList* coinListById(const int id) const throw(IndexException); + CoinList* coinListById(const int id) throw(IndexException); + int coinListIndex(const int id) const; + int coinListCount() const; CoinList* newCoinList(); - CoinList* newCoinList(const QString& fname); - CoinList* newCoinList(const CoinList& c); - void deleteCoinList(const int i) throw(IndexException); + CoinList* newCoinList(const QString& fileName); + CoinList* newCoinList(const CoinList& coinList); + void deleteCoinList(const int index) throw(IndexException); + void deleteCoinListById(const int id) throw(IndexException); - const Dialog* getDialog(const int i) const throw(IndexException); - Dialog* getDialog(const int i) throw(IndexException); - const Dialog* getDialogByID(const int i) const throw(IndexException); - Dialog* getDialogByID(const int i) throw(IndexException); - int getDialogIndex(const int i) const; - int getDialogCount() const; + const Dialog* dialog(const int index) const throw(IndexException); + Dialog* dialog(const int index) throw(IndexException); + const Dialog* dialogById(const int id) const throw(IndexException); + Dialog* dialogById(const int id) throw(IndexException); + int dialogIndex(const int id) const; + int dialogCount() const; Dialog* newDialog(); - Dialog* newDialog(const QString& fname); - Dialog* newDialog(const Dialog& d); - void deleteDialog(const int i) throw(IndexException); + Dialog* newDialog(const QString& fileName); + Dialog* newDialog(const Dialog& dialog); + void deleteDialog(const int index) throw(IndexException); + void deleteDialogById(const int id) throw(IndexException); - const EggGroup* getEggGroup(const int i) const throw(IndexException); - EggGroup* getEggGroup(const int i) throw(IndexException); - const EggGroup* getEggGroupByID(const int i) const throw(IndexException); - EggGroup* getEggGroupByID(const int i) throw(IndexException); - int getEggGroupIndex(const int i) const; - int getEggGroupCount() const; + const EggGroup* eggGroup(const int index) const throw(IndexException); + EggGroup* eggGroup(const int index) throw(IndexException); + const EggGroup* eggGroupById(const int id) const throw(IndexException); + EggGroup* eggGroupById(const int id) throw(IndexException); + int eggGroupIndex(const int id) const; + int eggGroupCount() const; EggGroup* newEggGroup(); - EggGroup* newEggGroup(const QString& fname); - EggGroup* newEggGroup(const EggGroup& e); - void deleteEggGroup(const int i) throw(IndexException); + EggGroup* newEggGroup(const QString& fileName); + EggGroup* newEggGroup(const EggGroup& eggGroup); + void deleteEggGroup(const int index) throw(IndexException); + void deleteEggGroupById(const int id) throw(IndexException); - const Item* getItem(const int i) const throw(IndexException); - Item* getItem(const int i) throw(IndexException); - const Item* getItemByID(const int i) const throw(IndexException); - Item* getItemByID(const int i) throw(IndexException); - int getItemIndex(const int i) const; - int getItemCount() const; + const Item* item(const int index) const throw(IndexException); + Item* item(const int index) throw(IndexException); + const Item* itemById(const int id) const throw(IndexException); + Item* itemById(const int id) throw(IndexException); + int itemIndex(const int id) const; + int itemCount() const; Item* newItem(); - Item* newItem(const QString& fname); - Item* newItem(const Item& i); - void deleteItem(const int i) throw(IndexException); + Item* newItem(const QString& fileName); + Item* newItem(const Item& item); + void deleteItem(const int index) throw(IndexException); + void deleteItemById(const int id) throw(IndexException); - const ItemType* getItemType(const int i) const throw(IndexException); - ItemType* getItemType(const int i) throw(IndexException); - const ItemType* getItemTypeByID(const int i) const throw(IndexException); - ItemType* getItemTypeByID(const int i) throw(IndexException); - int getItemTypeIndex(const int i) const; - int getItemTypeCount() const; + const ItemType* itemType(const int index) const throw(IndexException); + ItemType* itemType(const int index) throw(IndexException); + const ItemType* itemTypeById(const int id) const throw(IndexException); + ItemType* itemTypeById(const int id) throw(IndexException); + int itemTypeIndex(const int id) const; + int itemTypeCount() const; ItemType* newItemType(); - ItemType* newItemType(const QString& fname); - ItemType* newItemType(const ItemType& i); - void deleteItemType(const int i) throw(IndexException); + ItemType* newItemType(const QString& fileName); + ItemType* newItemType(const ItemType& itemType); + void deleteItemType(const int index) throw(IndexException); + void deleteItemTypeById(const int id) throw(IndexException); - const Map* getMap(const int i) const throw(IndexException); - Map* getMap(const int i) throw(IndexException); - const Map* getMapByID(const int i) const throw(IndexException); - Map* getMapByID(const int i) throw(IndexException); - int getMapIndex(const int i) const; - int getMapCount() const; + const Map* map(const int index) const throw(IndexException); + Map* map(const int index) throw(IndexException); + const Map* mapById(const int id) const throw(IndexException); + Map* mapById(const int id) throw(IndexException); + int mapIndex(const int id) const; + int mapCount() const; Map* newMap(); - Map* newMap(const QString& fname); - Map* newMap(const Map& m); - void deleteMap(const int i) throw(IndexException); + Map* newMap(const QString& fileName); + Map* newMap(const Map& map); + void deleteMap(const int index) throw(IndexException); + void deleteMapById(const int id) throw(IndexException); - const Move* getMove(const int i) const throw(IndexException); - Move* getMove(const int i) throw(IndexException); - const Move* getMoveByID(const int i) const throw(IndexException); - Move* getMoveByID(const int i) throw(IndexException); - int getMoveIndex(const int i) const; - int getMoveCount() const; + const Move* move(const int index) const throw(IndexException); + Move* move(const int index) throw(IndexException); + const Move* moveById(const int id) const throw(IndexException); + Move* moveById(const int id) throw(IndexException); + int moveIndex(const int id) const; + int moveCount() const; Move* newMove(); - Move* newMove(const QString& fname); - Move* newMove(const Move& m); - void deleteMove(const int i) throw(IndexException); + Move* newMove(const QString& fileName); + Move* newMove(const Move& move); + void deleteMove(const int index) throw(IndexException); + void deleteMoveById(const int id) throw(IndexException); - const Nature* getNature(const int i) const throw(IndexException); - Nature* getNature(const int i) throw(IndexException); - const Nature* getNatureByID(const int i) const throw(IndexException); - Nature* getNatureByID(const int i) throw(IndexException); - int getNatureIndex(const int i) const; - int getNatureCount() const; + const Nature* nature(const int index) const throw(IndexException); + Nature* nature(const int index) throw(IndexException); + const Nature* natureById(const int id) const throw(IndexException); + Nature* natureById(const int id) throw(IndexException); + int natureIndex(const int id) const; + int natureCount() const; Nature* newNature(); - Nature* newNature(const QString& fname); - Nature* newNature(const Nature& n); - void deleteNature(const int i) throw(IndexException); + Nature* newNature(const QString& fileName); + Nature* newNature(const Nature& nature); + void deleteNature(const int index) throw(IndexException); + void deleteNatureById(const int id) throw(IndexException); - const Species* getSpecies(const int i) const throw(IndexException); - Species* getSpecies(const int i) throw(IndexException); - const Species* getSpeciesByID(const int i) const throw(IndexException); - Species* getSpeciesByID(const int i) throw(IndexException); - int getSpeciesIndex(const int i) const; - int getSpeciesCount() const; + const Species* species(const int index) const throw(IndexException); + Species* species(const int index) throw(IndexException); + const Species* speciesById(const int id) const throw(IndexException); + Species* speciesById(const int id) throw(IndexException); + int speciesIndex(const int id) const; + int speciesCount() const; Species* newSpecies(); - Species* newSpecies(const QString& fname); - Species* newSpecies(const Species& s); - void deleteSpecies(const int i) throw(IndexException); + Species* newSpecies(const QString& fileName); + Species* newSpecies(const Species& species); + void deleteSpecies(const int index) throw(IndexException); + void deleteSpeciesById(const int id) throw(IndexException); - const Store* getStore(const int i) const throw(IndexException); - Store* getStore(const int i) throw(IndexException); - const Store* getStoreByID(const int i) const throw(IndexException); - Store* getStoreByID(const int i) throw(IndexException); - int getStoreIndex(const int i) const; - int getStoreCount() const; + const Store* store(const int index) const throw(IndexException); + Store* store(const int index) throw(IndexException); + const Store* storeById(const int id) const throw(IndexException); + Store* storeById(const int id) throw(IndexException); + int storeIndex(const int id) const; + int storeCount() const; Store* newStore(); - Store* newStore(const QString& fname); - Store* newStore(const Store& s); - void deleteStore(const int i) throw(IndexException); + Store* newStore(const QString& fileName); + Store* newStore(const Store& store); + void deleteStore(const int index) throw(IndexException); + void deleteStoreById(const int id) throw(IndexException); - const Tile* getTile(const int i) const throw(IndexException); - Tile* getTile(const int i) throw(IndexException); - const Tile* getTileByID(const int i) const throw(IndexException); - Tile* getTileByID(const int i) throw(IndexException); - int getTileIndex(const int i) const; - int getTileCount() const; + const Tile* tile(const int index) const throw(IndexException); + Tile* tile(const int index) throw(IndexException); + const Tile* tileById(const int id) const throw(IndexException); + Tile* tileById(const int id) throw(IndexException); + int tileIndex(const int id) const; + int tileCount() const; Tile* newTile(); - Tile* newTile(const QString& fname); - Tile* newTile(const Tile& t); - void deleteTile(const int i) throw(IndexException); + Tile* newTile(const QString& fileName); + Tile* newTile(const Tile& tile); + void deleteTile(const int index) throw(IndexException); + void deleteTileById(const int id) throw(IndexException); - const Time* getTime(const int i) const throw(IndexException); - Time* getTime(const int i) throw(IndexException); - const Time* getTimeByID(const int i) const throw(IndexException); - Time* getTimeByID(const int i) throw(IndexException); - int getTimeIndex(const int i) const; - int getTimeCount() const; + const Time* time(const int index) const throw(IndexException); + Time* time(const int index) throw(IndexException); + const Time* timeById(const int id) const throw(IndexException); + Time* timeById(const int id) throw(IndexException); + int timeIndex(const int id) const; + int timeCount() const; Time* newTime(); - Time* newTime(const QString& fname); - Time* newTime(const Time& t); - void deleteTime(const int i) throw(IndexException); + Time* newTime(const QString& fileName); + Time* newTime(const Time& time); + void deleteTime(const int index) throw(IndexException); + void deleteTimeById(const int id) throw(IndexException); - const Trainer* getTrainer(const int i) const throw(IndexException); - Trainer* getTrainer(const int i) throw(IndexException); - const Trainer* getTrainerByID(const int i) const throw(IndexException); - Trainer* getTrainerByID(const int i) throw(IndexException); - int getTrainerIndex(const int i) const; - int getTrainerCount() const; + const Trainer* trainer(const int index) const throw(IndexException); + Trainer* trainer(const int index) throw(IndexException); + const Trainer* trainerById(const int id) const throw(IndexException); + Trainer* trainerById(const int id) throw(IndexException); + int trainerIndex(const int id) const; + int trainerCount() const; Trainer* newTrainer(); - Trainer* newTrainer(const QString& fname); - Trainer* newTrainer(const Trainer& t); - void deleteTrainer(const int i) throw(IndexException); + Trainer* newTrainer(const QString& fileName); + Trainer* newTrainer(const Trainer& trainer); + void deleteTrainer(const int index) throw(IndexException); + void deleteTrainerById(const int id) throw(IndexException); - const Type* getType(const int i) const throw(IndexException); - Type* getType(const int i) throw(IndexException); - const Type* getTypeByID(const int i) const throw(IndexException); - Type* getTypeByID(const int i) throw(IndexException); - int getTypeIndex(const int i) const; - int getTypeCount() const; + const Type* type(const int index) const throw(IndexException); + Type* type(const int index) throw(IndexException); + const Type* typeById(const int id) const throw(IndexException); + Type* typeById(const int id) throw(IndexException); + int typeIndex(const int id) const; + int typeCount() const; Type* newType(); - Type* newType(const QString& fname); - Type* newType(const Type& t); - void deleteType(const int i) throw(IndexException); + Type* newType(const QString& fileName); + Type* newType(const Type& type); + void deleteType(const int index) throw(IndexException); + void deleteTypeById(const int id) throw(IndexException); Pokemod& operator=(const Pokemod& rhs); private: QStringList* valOutput; bool validate() const; - int getNewAbilityId() const; - int getNewAuthorId() const; - int getNewBadgeId() const; - int getNewCoinListId() const; - int getNewDialogId() const; - int getNewEggGroupId() const; - int getNewItemId() const; - int getNewItemTypeId() const; - int getNewMapId() const; - int getNewMoveId() const; - int getNewNatureId() const; - int getNewSpeciesId() const; - int getNewStoreId() const; - int getNewTileId() const; - int getNewTimeId() const; - int getNewTrainerId() const; - int getNewTypeId() const; + int newAbilityId() const; + int newAuthorId() const; + int newBadgeId() const; + int newCoinListId() const; + int newDialogId() const; + int newEggGroupId() const; + int newItemId() const; + int newItemTypeId() const; + int newMapId() const; + int newMoveId() const; + int newNatureId() const; + int newSpeciesId() const; + int newStoreId() const; + int newTileId() const; + int newTimeId() const; + int newTrainerId() const; + int newTypeId() const; void copyDir(const QString& src, const QString& dest) const; - QString title; - QString version; - QString description; - int startMap; - int startWarp; - QString superPCUname; - QString superPCPasswd; - Matrix<Frac> typeChart; - Rules rules; + QString m_title; + QString m_version; + QString m_description; + int m_startMap; + int m_startWarp; + QString m_superPCUname; + QString m_superPCPasswd; + Matrix<Frac> m_typeChart; + Rules m_rules; - QList<Ability*> abilities; - QList<Author*> authors; - QList<Badge*> badges; - QList<CoinList*> coinLists; - QList<Dialog*> dialogs; - QList<EggGroup*> eggGroups; - QList<Item*> items; - QList<ItemType*> itemTypes; - QList<Map*> maps; - QList<Move*> moves; - QList<Nature*> natures; - QList<Species*> species; - QList<Store*> stores; - QList<Tile*> tiles; - QList<Time*> times; - QList<Trainer*> trainers; - QList<Type*> types; + QList<Ability*> m_abilities; + QList<Author*> m_authors; + QList<Badge*> m_badges; + QList<CoinList*> m_coinLists; + QList<Dialog*> m_dialogs; + QList<EggGroup*> m_eggGroups; + QList<Item*> m_items; + QList<ItemType*> m_itemTypes; + QList<Map*> m_maps; + QList<Move*> m_moves; + QList<Nature*> m_natures; + QList<Species*> m_species; + QList<Store*> m_stores; + QList<Tile*> m_tiles; + QList<Time*> m_times; + QList<Trainer*> m_trainers; + QList<Type*> m_types; - QString path; + QString m_path; }; #endif diff --git a/pokemod/Rules.cpp b/pokemod/Rules.cpp index bbc67147..3d2f2ca8 100644 --- a/pokemod/Rules.cpp +++ b/pokemod/Rules.cpp @@ -1,492 +1,501 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Rules.h -// Purpose: Rules for a PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Mon Nov 19 14:54:12 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Pokemod includes #include "Pokemod.h" + +// Header include #include "Rules.h" const QStringList Rules::DVStr = QStringList() << "16" << "32"; -Rules::Rules(const Pokemod* par) : - Object("Rules", par, 0), - genderAllowed(false), - breedingAllowed(false), - holdItems(0), - criticalDomains(false), - abilityAllowed(false), - natureAllowed(false), - numBoxes(0), - boxSize(1), - maxParty(1), - maxFight(1), - maxMoves(1), - maxLevel(1), - maxMoney(0), - hardCash(false), - specialSplit(false), - specialDVSplit(false), - maxDVValue(0), - happiness(false), - happyFaintLoss(0), - happyLevelGain(0), - happySteps(0), - effortValuesAllowed(false), - maxTotalEV(0), - maxEVPerStat(0), - pokerusChance(1, 1) -{ -} - -Rules::Rules(const Pokemod* par, const Rules& r) : - Object("Rules", par, 0) -{ - *this = r; -} - -Rules::Rules(const Pokemod* par, const QString& fname) : - Object("Rules", par, 0) -{ - load(fname); +Rules::Rules(const Pokemod* pokemod) : + Object("Rules", pokemod, 0), + m_genderAllowed(false), + m_breedingAllowed(false), + m_holdItems(0), + m_criticalDomains(false), + m_abilityAllowed(false), + m_natureAllowed(false), + m_numBoxes(0), + m_boxSize(1), + m_maxParty(1), + m_maxFight(1), + m_maxPlayers(2), + m_maxMoves(1), + m_maxLevel(1), + m_maxMoney(0), + m_hardCash(false), + m_specialSplit(false), + m_specialDVSplit(false), + m_maxDVValue(0), + m_happiness(false), + m_happyFaintLoss(0), + m_happyLevelGain(0), + m_happySteps(0), + m_effortValuesAllowed(false), + m_maxTotalEV(0), + m_maxEVPerStat(0), + m_pokerusChance(1, 1) +{ +} + +Rules::Rules(const Pokemod* pokemod, const Rules& rules) : + Object("Rules", pokemod, 0) +{ + *this = rules; +} + +Rules::Rules(const Pokemod* pokemod, const QString& fileName) : + Object("Rules", pokemod, 0) +{ + load(fileName); } bool Rules::validate() const { bool valid = true; - pokemod->validationMsg("---Rules", Pokemod::V_Msg); - if (!numBoxes) - pokemod->validationMsg("No box storage", Pokemod::V_Warn); - else if (!boxSize) + pokemod()->validationMsg("---Rules", Pokemod::V_Msg); + if (!m_numBoxes) + pokemod()->validationMsg("No box storage", Pokemod::V_Warn); + else if (!m_boxSize) { - pokemod->validationMsg("Invalid box size"); + pokemod()->validationMsg("Invalid box size"); valid = false; } - if (!maxParty) + if (!m_maxParty) { - pokemod->validationMsg("Invalid party size"); + pokemod()->validationMsg("Invalid party size"); valid = false; } - if (!maxParty || (maxParty < maxFight)) + if (!m_maxParty || (m_maxParty < m_maxFight)) { - pokemod->validationMsg("Larger active than party"); + pokemod()->validationMsg("Larger active than party"); valid = false; } - if (!maxMoves) + if (m_maxPlayers < 2) { - pokemod->validationMsg("No moves can be learned"); + pokemod()->validationMsg("Cannot have battles without at least two players"); valid = false; } - if (!maxMoney) - pokemod->validationMsg("Player cannot carry any money", Pokemod::V_Warn); - if (1 < maxDVValue) + if (!m_maxMoves) + { + pokemod()->validationMsg("No moves can be learned"); + valid = false; + } + if (!m_maxMoney) + pokemod()->validationMsg("Player cannot carry any money", Pokemod::V_Warn); + if (1 < m_maxDVValue) { - pokemod->validationMsg("Invalid maximum DV value"); + pokemod()->validationMsg("Invalid maximum DV value"); valid = false; } - if (effortValuesAllowed) + if (m_effortValuesAllowed) { - if (maxTotalEV < maxEVPerStat) + if (m_maxTotalEV < m_maxEVPerStat) { - pokemod->validationMsg("More EV points are allowed on a stat than allowed overall"); + pokemod()->validationMsg("More EV points are allowed on a stat than allowed overall"); valid = false; } } - if (.005 < pokerusChance) - pokemod->validationMsg("Pokérus chance is unusually high", Pokemod::V_Warn); + if (.005 < m_pokerusChance) + pokemod()->validationMsg("Pokérus chance is unusually high", Pokemod::V_Warn); return valid; } -void Rules::load(const QString& fname, const int) throw(Exception) +void Rules::load(const QString& fileName, const int) throw(Exception) { - Ini ini(fname); + Ini ini(fileName); int i; int j; - ini.getValue("genderAllowed", genderAllowed, false); - ini.getValue("breedingAllowed", breedingAllowed, false); - ini.getValue("holdItems", holdItems, 0); - ini.getValue("criticalDomains", criticalDomains, false); - ini.getValue("abilityAllowed", abilityAllowed, false); - ini.getValue("natureAllowed", natureAllowed, false); - ini.getValue("numBoxes", numBoxes, 0); - ini.getValue("boxSize", boxSize, 1); - ini.getValue("maxParty", maxParty, 1); - ini.getValue("maxFight", maxFight, 1); - ini.getValue("maxMoves", maxMoves, 1); - ini.getValue("maxLevel", maxLevel, 0); - ini.getValue("maxMoney", maxMoney, 0); - ini.getValue("hardCash", hardCash, false); - ini.getValue("specialSplit", specialSplit, false); - ini.getValue("specialDVSplit", specialDVSplit, false); - ini.getValue("maxDVValue", maxDVValue, 16); - ini.getValue("happiness", happiness, false); - ini.getValue("happyFaintLoss", happyFaintLoss, 0); - ini.getValue("happyLevelGain", happyLevelGain, 0); - ini.getValue("happySteps", happySteps, 0); - ini.getValue("effortValuesAllowed", effortValuesAllowed, false); - ini.getValue("maxTotalEV", maxTotalEV, 0); - ini.getValue("maxEVPerStat", maxEVPerStat, 0); + ini.getValue("genderAllowed", m_genderAllowed, false); + ini.getValue("breedingAllowed", m_breedingAllowed, false); + ini.getValue("holdItems", m_holdItems, 0); + ini.getValue("criticalDomains", m_criticalDomains, false); + ini.getValue("abilityAllowed", m_abilityAllowed, false); + ini.getValue("natureAllowed", m_natureAllowed, false); + ini.getValue("numBoxes", m_numBoxes, 0); + ini.getValue("boxSize", m_boxSize, 1); + ini.getValue("maxParty", m_maxParty, 1); + ini.getValue("maxFight", m_maxFight, 1); + ini.getValue("maxPlayers", m_maxPlayers, 2); + ini.getValue("maxMoves", m_maxMoves, 1); + ini.getValue("maxLevel", m_maxLevel, 0); + ini.getValue("maxMoney", m_maxMoney, 0); + ini.getValue("hardCash", m_hardCash, false); + ini.getValue("specialSplit", m_specialSplit, false); + ini.getValue("specialDVSplit", m_specialDVSplit, false); + ini.getValue("maxDVValue", m_maxDVValue, 16); + ini.getValue("happiness", m_happiness, false); + ini.getValue("happyFaintLoss", m_happyFaintLoss, 0); + ini.getValue("happyLevelGain", m_happyLevelGain, 0); + ini.getValue("happySteps", m_happySteps, 0); + ini.getValue("effortValuesAllowed", m_effortValuesAllowed, false); + ini.getValue("maxTotalEV", m_maxTotalEV, 0); + ini.getValue("maxEVPerStat", m_maxEVPerStat, 0); ini.getValue("pokerusChance-n", i, 1); ini.getValue("pokerusChance-d", j, 1); - pokerusChance.set(i, j); + m_pokerusChance.set(i, j); } void Rules::save() const throw(Exception) { Ini ini; - ini.addField("genderAllowed", genderAllowed); - ini.addField("breedingAllowed", breedingAllowed); - ini.addField("holdItems", holdItems); - ini.addField("criticalDomains", criticalDomains); - ini.addField("abilityAllowed", abilityAllowed); - ini.addField("natureAllowed", natureAllowed); - ini.addField("numBoxes", numBoxes); - ini.addField("boxSize", boxSize); - ini.addField("maxParty", maxParty); - ini.addField("maxFight", maxFight); - ini.addField("maxMoves", maxMoves); - ini.addField("maxLevel", maxLevel); - ini.addField("maxMoney", maxMoney); - ini.addField("hardCash", hardCash); - ini.addField("specialSplit", specialSplit); - ini.addField("specialDVSplit", specialDVSplit); - ini.addField("maxDVValue", maxDVValue); - ini.addField("happiness", happiness); - ini.addField("happyFaintLoss", happyFaintLoss); - ini.addField("happyLevelGain", happyLevelGain); - ini.addField("happySteps", happySteps); - ini.addField("effortValuesAllowed", effortValuesAllowed); - ini.addField("maxTotalEV", maxTotalEV); - ini.addField("maxEVPerStat", maxEVPerStat); - ini.addField("pokerusChance-n", pokerusChance.getNum()); - ini.addField("pokerusChance-d", pokerusChance.getDenom()); - ini.save(QString("%1/rules.pini").arg(pokemod->getPath())); + ini.addField("genderAllowed", m_genderAllowed); + ini.addField("breedingAllowed", m_breedingAllowed); + ini.addField("holdItems", m_holdItems); + ini.addField("criticalDomains", m_criticalDomains); + ini.addField("abilityAllowed", m_abilityAllowed); + ini.addField("natureAllowed", m_natureAllowed); + ini.addField("numBoxes", m_numBoxes); + ini.addField("boxSize", m_boxSize); + ini.addField("maxParty", m_maxParty); + ini.addField("maxFight", m_maxFight); + ini.addField("maxPlayers", m_maxPlayers); + ini.addField("maxMoves", m_maxMoves); + ini.addField("maxLevel", m_maxLevel); + ini.addField("maxMoney", m_maxMoney); + ini.addField("hardCash", m_hardCash); + ini.addField("specialSplit", m_specialSplit); + ini.addField("specialDVSplit", m_specialDVSplit); + ini.addField("maxDVValue", m_maxDVValue); + ini.addField("happiness", m_happiness); + ini.addField("happyFaintLoss", m_happyFaintLoss); + ini.addField("happyLevelGain", m_happyLevelGain); + ini.addField("happySteps", m_happySteps); + ini.addField("effortValuesAllowed", m_effortValuesAllowed); + ini.addField("maxTotalEV", m_maxTotalEV); + ini.addField("maxEVPerStat", m_maxEVPerStat); + ini.addField("pokerusChance-n", m_pokerusChance.numerator()); + ini.addField("pokerusChance-d", m_pokerusChance.denominator()); + ini.save(QString("%1/rules.pini").arg(pokemod()->path())); } -void Rules::setGenderAllowed(const bool g) +void Rules::setGenderAllowed(const bool genderAllowed) { - genderAllowed = g; + m_genderAllowed = genderAllowed; } -void Rules::setBreedingAllowed(const bool b) +void Rules::setBreedingAllowed(const bool breedingAllowed) { - breedingAllowed = b; + m_breedingAllowed = breedingAllowed; } -void Rules::setHoldItems(const int h) +void Rules::setHoldItems(const int holdItems) { - holdItems = h; + m_holdItems = holdItems; } -void Rules::setCriticalDomains(const bool c) +void Rules::setCriticalDomains(const bool criticalDomains) { - criticalDomains = c; + m_criticalDomains = criticalDomains; } -void Rules::setAbilityAllowed(const bool a) +void Rules::setAbilityAllowed(const bool abilityAllowed) { - abilityAllowed = a; + m_abilityAllowed = abilityAllowed; } -void Rules::setNatureAllowed(const bool n) +void Rules::setNatureAllowed(const bool natureAllowed) { - natureAllowed = n; + m_natureAllowed = natureAllowed; } -void Rules::setNumBoxes(const int n) +void Rules::setNumBoxes(const int numBoxes) { - numBoxes = n; + m_numBoxes = numBoxes; } -void Rules::setBoxSize(const int b) +void Rules::setBoxSize(const int boxSize) { - boxSize = b; + m_boxSize = boxSize; } -void Rules::setMaxParty(const int m) throw(BoundsException) +void Rules::setMaxParty(const int maxParty) throw(BoundsException) { - if (!m) - throw(BoundsException(className, "maxParty")); - maxParty = m; - if (m < maxFight) - setMaxFight(m); + if (!maxParty) + throw(BoundsException(className(), "maxParty")); + m_maxParty = maxParty; + if (maxParty < m_maxFight) + setMaxFight(maxParty); } -void Rules::setMaxFight(const int m) throw(BoundsException) +void Rules::setMaxFight(const int maxFight) throw(BoundsException) { - if (maxParty < m) - throw(BoundsException(className, "maxFight")); - maxFight = m; + if (m_maxParty < maxFight) + throw(BoundsException(className(), "maxFight")); + m_maxFight = maxFight; } -void Rules::setMaxMoves(const int m) throw(BoundsException) +void Rules::setMaxPlayers(const int maxPlayers) throw(BoundsException) { - if (!m) - throw(BoundsException(className, "maxMoves")); - maxMoves = m; + if (!maxPlayers) + throw(BoundsException(className(), "maxPlayers")); + m_maxPlayers = maxPlayers; } -void Rules::setMaxLevel(const int m) throw(BoundsException) +void Rules::setMaxMoves(const int maxMoves) throw(BoundsException) { - if (!m) - throw(BoundsException(className, "maxLevel")); - maxLevel = m; + if (!maxMoves) + throw(BoundsException(className(), "maxMoves")); + m_maxMoves = maxMoves; } -void Rules::setMaxMoney(const int m) +void Rules::setMaxLevel(const int maxLevel) throw(BoundsException) { - maxMoney = m; + if (!maxLevel) + throw(BoundsException(className(), "maxLevel")); + m_maxLevel = maxLevel; } -void Rules::setHardCash(const bool h) +void Rules::setMaxMoney(const int maxMoney) { - hardCash = h; + m_maxMoney = maxMoney; } -void Rules::setSpecialSplit(const bool s) +void Rules::setHardCash(const bool hardCash) { - specialSplit = s; - if (!s) - setSpecialDVSplit(false); + m_hardCash = hardCash; } -void Rules::setSpecialDVSplit(const bool s) +void Rules::setSpecialSplit(const bool specialSplit) { - specialDVSplit = s; + m_specialSplit = specialSplit; + if (!specialSplit) + setSpecialDVSplit(false); } -void Rules::setMaxDVValue(const unsigned char m) throw(BoundsException) +void Rules::setSpecialDVSplit(const bool specialDVSplit) { - if (1 < m) - throw(BoundsException(className, "maxDVValue")); - maxDVValue = m; + m_specialDVSplit = specialDVSplit; } -void Rules::setHappiness(const bool h) +void Rules::setMaxDVValue(const unsigned char maxDVValue) throw(BoundsException) { - happiness = h; + if (1 < maxDVValue) + throw(BoundsException(className(), "maxDVValue")); + m_maxDVValue = maxDVValue; } -void Rules::setHappyFaintLoss(const int h) +void Rules::setHappiness(const bool happiness) { - happyFaintLoss = h; + m_happiness = happiness; } -void Rules::setHappyLevelGain(const int h) +void Rules::setHappyFaintLoss(const int happyFaintLoss) { - happyLevelGain = h; + m_happyFaintLoss = happyFaintLoss; } -void Rules::setHappySteps(const int h) +void Rules::setHappyLevelGain(const int happyLevelGain) { - happySteps = h; + m_happyLevelGain = happyLevelGain; } -void Rules::setEffortValuesAllowed(const bool e) +void Rules::setHappySteps(const int happySteps) { - effortValuesAllowed = e; + m_happySteps = happySteps; } -void Rules::setMaxTotalEV(const int m) throw(BoundsException) +void Rules::setEffortValuesAllowed(const bool effortValuesAllowed) { - if (!m) - throw(BoundsException(className, "maxTotalEV")); - maxTotalEV = m; - if (m < maxEVPerStat) - setMaxEVPerStat(m); + m_effortValuesAllowed = effortValuesAllowed; } -void Rules::setMaxEVPerStat(const int m) throw(BoundsException) +void Rules::setMaxTotalEV(const int maxTotalEV) throw(BoundsException) { - if (!m || (maxTotalEV < m)) - throw(BoundsException(className, "maxEVPerStat")); - maxEVPerStat = m; + if (!maxTotalEV) + throw(BoundsException(className(), "maxTotalEV")); + m_maxTotalEV = maxTotalEV; + if (maxTotalEV < m_maxEVPerStat) + setMaxEVPerStat(maxTotalEV); } -void Rules::setPokerusChance(const int n, const int d) throw(Exception) +void Rules::setMaxEVPerStat(const int maxEVPerStat) throw(BoundsException) { - pokerusChance.set(n, d); + if (!maxEVPerStat || (m_maxTotalEV < maxEVPerStat)) + throw(BoundsException(className(), "maxEVPerStat")); + m_maxEVPerStat = maxEVPerStat; } -void Rules::setPokerusChanceNum(const int n) throw(Exception) +void Rules::setPokerusChance(const int numerator, const int denominator) throw(Exception) { - pokerusChance.setNum(n); + m_pokerusChance.set(numerator, denominator); } -void Rules::setPokerusChanceDenom(const int d) throw(Exception) +bool Rules::genderAllowed() const { - pokerusChance.setDenom(d); + return m_genderAllowed; } -bool Rules::getGenderAllowed() const +bool Rules::breedingAllowed() const { - return genderAllowed; + return m_breedingAllowed; } -bool Rules::getBreedingAllowed() const +int Rules::holdItems() const { - return breedingAllowed; + return m_holdItems; } -int Rules::getHoldItems() const +bool Rules::criticalDomains() const { - return holdItems; + return m_criticalDomains; } -bool Rules::getCriticalDomains() const +bool Rules::abilityAllowed() const { - return criticalDomains; + return m_abilityAllowed; } -bool Rules::getAbilityAllowed() const +bool Rules::natureAllowed() const { - return abilityAllowed; + return m_natureAllowed; } -bool Rules::getNatureAllowed() const +int Rules::numBoxes() const { - return natureAllowed; + return m_numBoxes; } -int Rules::getNumBoxes() const +int Rules::boxSize() const { - return numBoxes; + return m_boxSize; } -int Rules::getBoxSize() const +int Rules::maxParty() const { - return boxSize; + return m_maxParty; } -int Rules::getMaxParty() const +int Rules::maxFight() const { - return maxParty; + return m_maxFight; } -int Rules::getMaxFight() const +int Rules::maxPlayers() const { - return maxFight; + return m_maxPlayers; } -int Rules::getMaxMoves() const +int Rules::maxMoves() const { - return maxMoves; + return m_maxMoves; } -int Rules::getMaxLevel() const +int Rules::maxLevel() const { - return maxLevel; + return m_maxLevel; } -int Rules::getMaxMoney() const +int Rules::maxMoney() const { - return maxMoney; + return m_maxMoney; } -bool Rules::getHardCash() const +bool Rules::hardCash() const { - return hardCash; + return m_hardCash; } -bool Rules::getSpecialSplit() const +bool Rules::specialSplit() const { - return specialSplit; + return m_specialSplit; } -bool Rules::getSpecialDVSplit() const +bool Rules::specialDVSplit() const { - return specialDVSplit; + return m_specialDVSplit; } -unsigned char Rules::getMaxDVValue() const +unsigned char Rules::maxDVValue() const { - return maxDVValue; + return m_maxDVValue; } -bool Rules::getHappiness() const +bool Rules::happiness() const { - return happiness; + return m_happiness; } -int Rules::getHappyFaintLoss() const +int Rules::happyFaintLoss() const { - return happyFaintLoss; + return m_happyFaintLoss; } -int Rules::getHappyLevelGain() const +int Rules::happyLevelGain() const { - return happyLevelGain; + return m_happyLevelGain; } -int Rules::getHappySteps() const +int Rules::happySteps() const { - return happySteps; + return m_happySteps; } -bool Rules::getEffortValuesAllowed() const +bool Rules::effortValuesAllowed() const { - return effortValuesAllowed; + return m_effortValuesAllowed; } -int Rules::getMaxTotalEV() const +int Rules::maxTotalEV() const { - return maxTotalEV; + return m_maxTotalEV; } -int Rules::getMaxEVPerStat() const +int Rules::maxEVPerStat() const { - return maxEVPerStat; + return m_maxEVPerStat; } -Frac Rules::getPokerusChance() const +Frac Rules::pokerusChance() const { - return pokerusChance; + return m_pokerusChance; } Rules& Rules::operator=(const Rules& rhs) { if (this == &rhs) return *this; - genderAllowed = rhs.genderAllowed; - breedingAllowed = rhs.breedingAllowed; - holdItems = rhs.holdItems; - criticalDomains = rhs.criticalDomains; - abilityAllowed = rhs.abilityAllowed; - natureAllowed = rhs.natureAllowed; - numBoxes = rhs.numBoxes; - boxSize = rhs.boxSize; - maxParty = rhs.maxParty; - maxFight = rhs.maxFight; - maxMoves = rhs.maxMoves; - maxLevel = rhs.maxLevel; - maxMoney = rhs.maxMoney; - hardCash = rhs.hardCash; - specialSplit = rhs.specialSplit; - specialDVSplit = rhs.specialDVSplit; - maxDVValue = rhs.maxDVValue; - happiness = rhs.happiness; - happyFaintLoss = rhs.happyFaintLoss; - happyLevelGain = rhs.happyLevelGain; - happySteps = rhs.happySteps; - effortValuesAllowed = rhs.effortValuesAllowed; - maxTotalEV = rhs.maxTotalEV; - maxEVPerStat = rhs.maxEVPerStat; - pokerusChance = rhs.pokerusChance; + m_genderAllowed = rhs.m_genderAllowed; + m_breedingAllowed = rhs.m_breedingAllowed; + m_holdItems = rhs.m_holdItems; + m_criticalDomains = rhs.m_criticalDomains; + m_abilityAllowed = rhs.m_abilityAllowed; + m_natureAllowed = rhs.m_natureAllowed; + m_numBoxes = rhs.m_numBoxes; + m_boxSize = rhs.m_boxSize; + m_maxParty = rhs.m_maxParty; + m_maxFight = rhs.m_maxFight; + m_maxPlayers = rhs.m_maxPlayers; + m_maxMoves = rhs.m_maxMoves; + m_maxLevel = rhs.m_maxLevel; + m_maxMoney = rhs.m_maxMoney; + m_hardCash = rhs.m_hardCash; + m_specialSplit = rhs.m_specialSplit; + m_specialDVSplit = rhs.m_specialDVSplit; + m_maxDVValue = rhs.m_maxDVValue; + m_happiness = rhs.m_happiness; + m_happyFaintLoss = rhs.m_happyFaintLoss; + m_happyLevelGain = rhs.m_happyLevelGain; + m_happySteps = rhs.m_happySteps; + m_effortValuesAllowed = rhs.m_effortValuesAllowed; + m_maxTotalEV = rhs.m_maxTotalEV; + m_maxEVPerStat = rhs.m_maxEVPerStat; + m_pokerusChance = rhs.m_pokerusChance; return *this; } diff --git a/pokemod/Rules.h b/pokemod/Rules.h index 199a6920..eb57c106 100644 --- a/pokemod/Rules.h +++ b/pokemod/Rules.h @@ -1,35 +1,34 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Rules.h -// Purpose: Rules for a PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Mon Nov 19 14:08:30 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class Rules : public Object @@ -37,96 +36,97 @@ class Rules : public Object public: static const QStringList DVStr; - Rules(const Pokemod* par); - Rules(const Pokemod* par, const Rules& r); - Rules(const Pokemod* par, const QString& fname); + Rules(const Pokemod* pokemod); + Rules(const Pokemod* pokemod, const Rules& rules); + Rules(const Pokemod* pokemod, const QString& fileName); - void load(const QString& fname, const int = 0) throw(Exception); + void load(const QString& fileName, const int = 0) throw(Exception); void save() const throw(Exception); - void setGenderAllowed(const bool g); - void setBreedingAllowed(const bool b); - void setHoldItems(const int h); - void setCriticalDomains(const bool c); - void setAbilityAllowed(const bool a); - void setNatureAllowed(const bool n); - void setNumBoxes(const int n); - void setBoxSize(const int b); - void setMaxParty(const int m) throw(BoundsException); - void setMaxFight(const int m) throw(BoundsException); - void setMaxMoves(const int m) throw(BoundsException); - void setMaxLevel(const int m) throw(BoundsException); - void setMaxMoney(const int m); - void setHardCash(const bool h); - void setSpecialSplit(const bool s); - void setSpecialDVSplit(const bool s); - void setMaxDVValue(const unsigned char m) throw(BoundsException); - void setHappiness(const bool h); - void setHappyFaintLoss(const int h); - void setHappyLevelGain(const int h); - void setHappySteps(const int h); - void setEffortValuesAllowed(const bool e); - void setMaxTotalEV(const int m) throw(BoundsException); - void setMaxEVPerStat(const int m) throw(BoundsException); - void setPokerusChance(const int n, const int d) throw(Exception); - void setPokerusChanceNum(const int n) throw(Exception); - void setPokerusChanceDenom(const int d) throw(Exception); + void setGenderAllowed(const bool genderAllowed); + void setBreedingAllowed(const bool breedingAllowed); + void setHoldItems(const int holdItems); + void setCriticalDomains(const bool criticalDomains); + void setAbilityAllowed(const bool abilityAllowed); + void setNatureAllowed(const bool natureAllowed); + void setNumBoxes(const int numBoxes); + void setBoxSize(const int boxSize); + void setMaxParty(const int maxParty) throw(BoundsException); + void setMaxFight(const int maxFight) throw(BoundsException); + void setMaxPlayers(const int maxPlayers) throw(BoundsException); + void setMaxMoves(const int maxMoves) throw(BoundsException); + void setMaxLevel(const int maxLevel) throw(BoundsException); + void setMaxMoney(const int maxMoney); + void setHardCash(const bool hardCash); + void setSpecialSplit(const bool specialSplit); + void setSpecialDVSplit(const bool specialDVSplit); + void setMaxDVValue(const unsigned char maxDV) throw(BoundsException); + void setHappiness(const bool happiness); + void setHappyFaintLoss(const int happyFaint); + void setHappyLevelGain(const int happyLevel); + void setHappySteps(const int happySteps); + void setEffortValuesAllowed(const bool effortValues); + void setMaxTotalEV(const int maxTotalEV) throw(BoundsException); + void setMaxEVPerStat(const int maxEVPerStat) throw(BoundsException); + void setPokerusChance(const int numerator, const int denominator) throw(Exception); - bool getGenderAllowed() const; - bool getBreedingAllowed() const; - int getHoldItems() const; - bool getCriticalDomains() const; - bool getAbilityAllowed() const; - bool getNatureAllowed() const; - int getNumBoxes() const; - int getBoxSize() const; - int getMaxParty() const; - int getMaxFight() const; - int getMaxMoves() const; - int getMaxLevel() const; - int getMaxMoney() const; - bool getHardCash() const; - bool getSpecialSplit() const; - bool getSpecialDVSplit() const; - unsigned char getMaxDVValue() const; - bool getHappiness() const; - int getHappyFaintLoss() const; - int getHappyLevelGain() const; - int getHappySteps() const; - bool getEffortValuesAllowed() const; - int getMaxTotalEV() const; - int getMaxEVPerStat() const; - Frac getPokerusChance() const; + bool genderAllowed() const; + bool breedingAllowed() const; + int holdItems() const; + bool criticalDomains() const; + bool abilityAllowed() const; + bool natureAllowed() const; + int numBoxes() const; + int boxSize() const; + int maxParty() const; + int maxFight() const; + int maxPlayers() const; + int maxMoves() const; + int maxLevel() const; + int maxMoney() const; + bool hardCash() const; + bool specialSplit() const; + bool specialDVSplit() const; + unsigned char maxDVValue() const; + bool happiness() const; + int happyFaintLoss() const; + int happyLevelGain() const; + int happySteps() const; + bool effortValuesAllowed() const; + int maxTotalEV() const; + int maxEVPerStat() const; + Frac pokerusChance() const; Rules& operator=(const Rules& rhs); private: bool validate() const; - bool genderAllowed; - bool breedingAllowed; - int holdItems; - bool criticalDomains; - bool abilityAllowed; - bool natureAllowed; - int numBoxes; - int boxSize; - int maxParty; - int maxFight; - int maxMoves; - int maxLevel; - int maxMoney; - bool hardCash; - bool specialSplit; - bool specialDVSplit; - unsigned char maxDVValue; - bool happiness; - int happyFaintLoss; - int happyLevelGain; - int happySteps; - bool effortValuesAllowed; - int maxTotalEV; - int maxEVPerStat; - Frac pokerusChance; + bool m_genderAllowed; + bool m_breedingAllowed; + int m_holdItems; + bool m_criticalDomains; + bool m_abilityAllowed; + bool m_natureAllowed; + int m_numBoxes; + int m_boxSize; + int m_maxParty; + int m_maxFight; + int m_maxPlayers; + int m_maxMoves; + int m_maxLevel; + int m_maxMoney; + bool m_hardCash; + bool m_specialSplit; + bool m_specialDVSplit; + unsigned char m_maxDVValue; + bool m_happiness; + int m_happyFaintLoss; + int m_happyLevelGain; + int m_happySteps; + bool m_effortValuesAllowed; + int m_maxTotalEV; + int m_maxEVPerStat; + Frac m_pokerusChance; }; #endif diff --git a/pokemod/Species.cpp b/pokemod/Species.cpp index b397993d..bda6e20e 100644 --- a/pokemod/Species.cpp +++ b/pokemod/Species.cpp @@ -1,429 +1,331 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Species.cpp -// Purpose: Define a species -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri June 1 2007 12:10:40 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// - +/* + * 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/>. + */ + +// Qt includes #include <QDir> -#include <QListIterator> #include <QMap> -#include <QMapIterator> -#include <QStringListIterator> +// Pokemod includes #include "Pokemod.h" #include "SpeciesAbility.h" #include "SpeciesEvolution.h" #include "SpeciesItem.h" #include "SpeciesMove.h" + +// Header include #include "Species.h" const QStringList Species::StyleStr = QStringList() << "Fluctuating" << "Fading" << "Slow" << "Normal" << "Fast" << "Erratic"; -Species::Species(const Pokemod* par, const int _id) : - Object("Species", par, _id), - name(""), - growth(-1), - catchValue(0), - runChance(1, 1), - fleeChance(1, 1), - itemChance(1, 1), - pokedexNumber(-1), - weight(0), - heightFeet(0), - heightInches(0), - pokedexEntry(""), - genderFactor(1, 1), - eggSpecies(-1), - eggSteps(0), - nidoranGroup(-1) +Species::Species(const Pokemod* pokemod, const int id) : + Object("Species", pokemod, id), + m_name(""), + m_growth(INT_MAX), + m_catchValue(0), + m_runChance(1, 1), + m_fleeChance(1, 1), + m_itemChance(1, 1), + m_pokedexNumber(INT_MAX), + m_weight(0), + m_heightFeet(0), + m_heightInches(0), + m_pokedexEntry(""), + m_genderFactor(1, 1), + m_eggSpecies(INT_MAX), + m_eggSteps(0), + m_nidoranGroup(INT_MAX) { for (int i = 0; i < Pokemod::ST_End_GSC; ++i) { - baseStats[i] = 0; - effortValues[i] = 0; + m_baseStats[i] = 0; + m_effortValues[i] = 0; } } -Species::Species(const Pokemod* par, const Species& s, const int _id) : - Object("Species", par, _id) +Species::Species(const Pokemod* pokemod, const Species& species, const int id) : + Object("Species", pokemod, id) { - *this = s; + *this = species; } -Species::Species(const Pokemod* par, const QString& fname, const int _id) : - Object("Species", par, _id) +Species::Species(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Species", pokemod, id) { - load(fname, _id); + load(fileName, id); } Species::~Species() { - for (QListIterator<SpeciesAbility*> i(abilities); i.hasNext(); ) - delete i.next(); - for (QListIterator<SpeciesEvolution*> i(evolutions); i.hasNext(); ) - delete i.next(); - for (QListIterator<SpeciesItem*> i(items); i.hasNext(); ) - delete i.next(); - for (QListIterator<SpeciesMove*> i(moves); i.hasNext(); ) - delete i.next(); + foreach (SpeciesAbility* ability, m_abilities) + delete ability; + foreach (SpeciesEvolution* evolution, m_evolutions) + delete evolution; + foreach (SpeciesItem* item, m_items) + delete item; + foreach (SpeciesMove* move, m_moves) + delete move; } bool Species::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Species \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Species \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - for (int i = 0; i < (pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY); ++i) + for (int i = 0; i < (pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY); ++i) { - if (!baseStats[i]) + if (!m_baseStats[i]) { - pokemod->validationMsg(QString("Invalid baseStats[%1]").arg(i)); + pokemod()->validationMsg(QString("Invalid baseStats[%1]").arg(i)); valid = false; } } - if (End <= growth) + if (End <= m_growth) { - pokemod->validationMsg("Invalid growth style"); + pokemod()->validationMsg("Invalid growth style"); valid = false; } - if (pokemod->getSpeciesCount() <= pokedexNumber) + if (!m_weight) + pokemod()->validationMsg("Species weighs nothing", Pokemod::V_Warn); + if (12 <= m_heightInches) { - pokemod->validationMsg("Invalid PokéDex number"); + pokemod()->validationMsg("Invalid height inches"); valid = false; } - if (!weight) - pokemod->validationMsg("Species weighs nothing", Pokemod::V_Warn); - if (12 <= heightInches) + if (!QFile::exists(frontMaleSprite())) { - pokemod->validationMsg("Invalid height inches"); + pokemod()->validationMsg(QString("Cannot find the front%1 image").arg(pokemod()->rules()->genderAllowed() ? " male" : "")); valid = false; } - if (!QFile::exists(getFrontMaleSprite())) + if (!QFile::exists(backMaleSprite())) { - pokemod->validationMsg(QString("Cannot find the front%1 image").arg(pokemod->getRules()->getGenderAllowed() ? " male" : "")); + pokemod()->validationMsg(QString("Cannot find the back%1 image").arg(pokemod()->rules()->genderAllowed() ? " male" : "")); valid = false; } - if (!QFile::exists(getBackMaleSprite())) + if (pokemod()->rules()->genderAllowed()) { - pokemod->validationMsg(QString("Cannot find the back%1 image").arg(pokemod->getRules()->getGenderAllowed() ? " male" : "")); - valid = false; - } - if (pokemod->getRules()->getGenderAllowed()) - { - if (!QFile::exists(getFrontFemaleSprite())) + if (!QFile::exists(frontFemaleSprite())) { - pokemod->validationMsg("Cannot find the front female image"); + pokemod()->validationMsg("Cannot find the front female image"); valid = false; } - if (!QFile::exists(getBackFemaleSprite())) + if (!QFile::exists(backFemaleSprite())) { - pokemod->validationMsg("Cannot find the back female image"); + pokemod()->validationMsg("Cannot find the back female image"); valid = false; } } - if (!QFile::exists(getListSprite())) - { - pokemod->validationMsg("Cannot find the list sprite"); - valid = false; - } - if (pokemod->getSpeciesIndex(eggSpecies) == -1) - pokemod->validationMsg("Invalid egg species", Pokemod::V_Warn); - else if (!eggSteps) + if (!QFile::exists(listSprite())) { - pokemod->validationMsg("Invalid egg steps"); + pokemod()->validationMsg("Cannot find the list sprite"); valid = false; } - QMap<int, int> idChecker; - QMap<int, int> nameChecker; - for (QListIterator<int> i(types); i.hasNext(); i.next()) + if (pokemod()->speciesIndex(m_eggSpecies) == INT_MAX) + pokemod()->validationMsg("Invalid egg species", Pokemod::V_Warn); + else { - if (pokemod->getTypeIndex(i.peekNext()) == -1) + if (pokemod()->species(m_eggSpecies)->growth() != m_growth) { - pokemod->validationMsg("Invalid type"); + pokemod()->validationMsg("Growth styles do not match for egg species"); valid = false; } - ++nameChecker[i.peekNext()]; - } - for (QMapIterator<int, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + if (!m_eggSteps) { - pokemod->validationMsg(QString("There are %1 of type %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid egg steps"); valid = false; } } - nameChecker.clear(); - for (QListIterator<int> i(eggGroups); i.hasNext(); i.next()) + QMap<int, bool> idChecker; + QMap<int, bool> valueChecker; + foreach (int type, m_types) { - if (pokemod->getEggGroupIndex(i.peekNext()) == -1) + if (pokemod()->typeIndex(type) == INT_MAX) { - pokemod->validationMsg("Invalid egg group"); + pokemod()->validationMsg("Invalid type"); valid = false; } - ++nameChecker[i.peekNext()]; + if (valueChecker[type]) + pokemod()->validationMsg(QString("Duplicate of type %1").arg(type)); + valueChecker[type] = true; } - for (QMapIterator<int, int> i(nameChecker); i.hasNext(); i.next()) + valueChecker.clear(); + foreach (int eggGroup, m_eggGroups) { - if (1 < i.value()) + if (pokemod()->eggGroupIndex(eggGroup) == INT_MAX) { - pokemod->validationMsg(QString("There are %1 of egg group %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid egg group"); valid = false; } + if (valueChecker[eggGroup]) + pokemod()->validationMsg(QString("Duplicate of egg group %1").arg(eggGroup)); + valueChecker[eggGroup] = true; } - nameChecker.clear(); - if (pokemod->getRules()->getAbilityAllowed()) + valueChecker.clear(); + if (pokemod()->rules()->abilityAllowed()) { - if (!getAbilityCount()) - pokemod->validationMsg("There are no abilities", Pokemod::V_Warn); - for (QListIterator<SpeciesAbility*> i(abilities); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getAbility()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 abilities with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<int, int> i(nameChecker); i.hasNext(); i.next()) + if (!abilityCount()) + pokemod()->validationMsg("There are no m_abilities", Pokemod::V_Warn); + foreach (SpeciesAbility* ability, m_abilities) { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 abilities with the ability %2").arg(i.value()).arg(i.key())); + if (!ability->isValid()) valid = false; - } + if (idChecker[ability->id()]) + pokemod()->validationMsg(QString("Duplicate ability with id %1").arg(ability->id())); + idChecker[ability->id()] = true; + if (valueChecker[ability->ability()]) + pokemod()->validationMsg(QString("Duplicate of ability %1").arg(ability->ability())); + valueChecker[ability->ability()] = true; } idChecker.clear(); - nameChecker.clear(); + valueChecker.clear(); } - if (!getEvolutionCount()) - pokemod->validationMsg("There are no evolutions", Pokemod::V_Warn); - for (QListIterator<SpeciesEvolution*> i(evolutions); i.hasNext(); i.next()) + if (!evolutionCount()) + pokemod()->validationMsg("There are no m_evolutions", Pokemod::V_Warn); + foreach (SpeciesEvolution* evolution, m_evolutions) { - if (!i.peekNext()->isValid()) + if (!evolution->isValid()) valid = false; - if (i.peekNext()->getSpecies() == id) + if (evolution->species() == id()) { - pokemod->validationMsg("Evolution is of the same species"); + pokemod()->validationMsg("Evolution is of the same species"); valid = false; } - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getSpecies()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) + if (pokemod()->species(evolution->species())->growth() != m_growth) { - pokemod->validationMsg(QString("There are %1 evolutions with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<int, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 evolutions with the species %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Growth styles do not match for m_evolutions"); valid = false; } + if (idChecker[evolution->id()]) + pokemod()->validationMsg(QString("Duplicate evolution with id %1").arg(evolution->id())); + idChecker[evolution->id()] = true; } idChecker.clear(); - nameChecker.clear(); - if (pokemod->getRules()->getHoldItems()) + if (pokemod()->rules()->holdItems()) { - if (!getItemCount()) - pokemod->validationMsg("There are no items", Pokemod::V_Warn); - for (QListIterator<SpeciesItem*> i(items); i.hasNext(); i.next()) + if (!itemCount()) + pokemod()->validationMsg("There are no m_items", Pokemod::V_Warn); + foreach (SpeciesItem* item, m_items) { - if (!i.peekNext()->isValid()) + if (!item->isValid()) valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getItem()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 items with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<int, int> i(nameChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 items with the item %2").arg(i.value()).arg(i.key())); - valid = false; - } + if (idChecker[item->id()]) + pokemod()->validationMsg(QString("Duplicate item with id %1").arg(item->id())); + idChecker[item->id()] = true; + if (valueChecker[item->item()]) + pokemod()->validationMsg(QString("Duplicate of item %1").arg(item->item())); + valueChecker[item->item()] = true; } idChecker.clear(); - nameChecker.clear(); + valueChecker.clear(); } - if (!getMoveCount()) + if (!moveCount()) { - pokemod->validationMsg("There are no moves"); + pokemod()->validationMsg("There are no m_moves"); valid = false; } - for (QListIterator<SpeciesMove*> i(moves); i.hasNext(); i.next()) - { - if (!i.peekNext()->isValid()) - valid = false; - ++idChecker[i.peekNext()->getId()]; - ++nameChecker[i.peekNext()->getMove()]; - } - for (QMapIterator<int, int> i(idChecker); i.hasNext(); i.next()) - { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 moves with id %2").arg(i.value()).arg(i.key())); - valid = false; - } - } - for (QMapIterator<int, int> i(nameChecker); i.hasNext(); i.next()) + foreach (SpeciesMove* move, m_moves) { - if (1 < i.value()) - { - pokemod->validationMsg(QString("There are %1 moves with the move %2").arg(i.value()).arg(i.key())); + if (!move->isValid()) valid = false; - } + if (idChecker[move->id()]) + pokemod()->validationMsg(QString("Duplicate move with id %1").arg(move->id())); + idChecker[move->id()] = true; } - idChecker.clear(); - nameChecker.clear(); return valid; } -int Species::getNewAbilityId() const -{ - int i = 0; - for (; (i < getAbilityCount()) && (getAbilityIndex(i) != -1); ++i) - ; - return i; -} - -int Species::getNewEvolutionId() const +void Species::load(const QString& fileName, int id) throw(Exception) { - int i = 0; - for (; (i < getEvolutionCount()) && (getEvolutionIndex(i) != -1); ++i) - ; - return i; -} - -int Species::getNewItemId() const -{ - int i = 0; - for (; (i < getItemCount()) && (getItemIndex(i) != -1); ++i) - ; - return i; -} - -int Species::getNewMoveId() const -{ - int i = 0; - for (; (i < getMoveCount()) && (getMoveIndex(i) != -1); ++i) - ; - return i; -} - -void Species::load(const QString& fname, const int _id) throw(Exception) -{ - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - ini.getValue(QString("baseStats-%d").arg(i), baseStats[i], 0); + ini.getValue(QString("baseStats-%d").arg(i), m_baseStats[i], 0); for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - ini.getValue(QString("effortValues-%1").arg(i), effortValues[i], 0); - ini.getValue("growth", growth); - ini.getValue("experienceValue", experienceValue, 0); - ini.getValue("catchValue", catchValue, 0); + ini.getValue(QString("effortValues-%1").arg(i), m_effortValues[i], 0); + ini.getValue("growth", m_growth); + ini.getValue("experienceValue", m_experienceValue, 0); + ini.getValue("catchValue", m_catchValue, 0); ini.getValue("runChance-n", i, 1); ini.getValue("runChance-d", j, 1); - runChance.set(i, j); + m_runChance.set(i, j); ini.getValue("fleeChance-n", i, 1); ini.getValue("fleeChance-d", j, 1); - fleeChance.set(i, j); + m_fleeChance.set(i, j); ini.getValue("itemChance-i", i, 1); ini.getValue("itemChance-j", j, 1); - itemChance.set(i, j); - ini.getValue("pokedexNumber", pokedexNumber); - ini.getValue("weight", weight, 0); - ini.getValue("heightFeet", heightFeet, 0); - ini.getValue("heightInches", heightInches, 0); - ini.getValue("pokedexEntry", pokedexEntry); + m_itemChance.set(i, j); + ini.getValue("pokedexNumber", m_pokedexNumber); + ini.getValue("weight", m_weight, 0); + ini.getValue("heightFeet", m_heightFeet, 0); + ini.getValue("heightInches", m_heightInches, 0); + ini.getValue("pokedexEntry", m_pokedexEntry); ini.getValue("genderFactor-n", i, 1); ini.getValue("genderFactor-d", j, 1); - genderFactor.set(i, j, true); - ini.getValue("eggSpecies", eggSpecies); - ini.getValue("eggSteps", eggSteps, 0); - ini.getValue("nidoranGroup", nidoranGroup); + m_genderFactor.set(i, j, true); + ini.getValue("eggSpecies", m_eggSpecies); + ini.getValue("eggSteps", m_eggSteps, 0); + ini.getValue("nidoranGroup", m_nidoranGroup); ini.getValue("numTypes", i); for (int k = 0; k < i; ++k) { ini.getValue(QString("type-%1").arg(i), j); - if (j != -1) - types.append(j); + if (!m_types.contains(j)) + m_types.append(j); } ini.getValue("numEggGroups", i); for (int k = 0; k < i; ++k) { ini.getValue(QString("eggGroup-%1").arg(i), j); - if (j != -1) - types.append(j); + if (!m_eggGroups.contains(j)) + m_eggGroups.append(j); } - QStringList path = pokemod->getPath().split('/'); + QStringList path = pokemod()->path().split('/'); path.removeLast(); QDir fdir(path.join("/")); - abilities.clear(); + m_abilities.clear(); if (fdir.cd("ability")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) newAbility(i.next()); fdir.cdUp(); } - evolutions.clear(); + m_evolutions.clear(); if (fdir.cd("evolution")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) newEvolution(i.next()); fdir.cdUp(); } - items.clear(); + m_items.clear(); if (fdir.cd("item")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) newItem(i.next()); fdir.cdUp(); } - moves.clear(); + m_moves.clear(); if (fdir.cd("move")) { for (QStringListIterator i(fdir.entryList(QStringList("*.pini"), QDir::Files, QDir::Name)); i.hasNext(); ) @@ -434,716 +336,706 @@ void Species::load(const QString& fname, const int _id) throw(Exception) void Species::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); + ini.addField("id", id()); + ini.addField("name", m_name); for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - ini.addField(QString("baseStats-%1").arg(i), baseStats[i]); + ini.addField(QString("baseStats-%1").arg(i), m_baseStats[i]); for (int i = 0; i < Pokemod::ST_End_GSC; ++i) - ini.addField(QString("effortValues-%1").arg(i), effortValues[i]); - ini.addField("growth", growth); - ini.addField("experienceValue", experienceValue); - ini.addField("catchValue", catchValue); - ini.addField("runChance-n", runChance.getNum()); - ini.addField("runChance-d", runChance.getDenom()); - ini.addField("fleeChance-n", fleeChance.getNum()); - ini.addField("fleeChance-d", fleeChance.getDenom()); - ini.addField("itemChance-n", itemChance.getNum()); - ini.addField("itemChance-d", itemChance.getDenom()); - ini.addField("pokedexNumber", pokedexNumber); - ini.addField("weight", weight); - ini.addField("heightFeet", heightFeet); - ini.addField("heightInches", heightInches); - ini.addField("pokedexEntry", pokedexEntry); - ini.addField("genderFactor-n", genderFactor.getNum()); - ini.addField("genderFactor-d", genderFactor.getDenom()); - ini.addField("eggSpecies", eggSpecies); - ini.addField("eggSteps", eggSteps); - ini.addField("nidoranGroup", nidoranGroup); - ini.addField("numTypes", types.size()); - for (int i = 0; i < types.size(); ++i) - ini.addField(QString("type-%1").arg(i), types[i]); - ini.addField("numEggGroups", eggGroups.size()); - for (int i = 0; i < eggGroups.size(); ++i) - ini.addField(QString("eggGroup-%1").arg(i), eggGroups[i]); - ini.save(QString("%1/species/%2/data.pini").arg(pokemod->getPath()).arg(name)); - for (QListIterator<SpeciesAbility*> i(abilities); i.hasNext(); ) - i.next()->save(name); - for (QListIterator<SpeciesEvolution*> i(evolutions); i.hasNext(); ) - i.next()->save(name); - for (QListIterator<SpeciesItem*> i(items); i.hasNext(); ) - i.next()->save(name); - for (QListIterator<SpeciesMove*> i(moves); i.hasNext(); ) - i.next()->save(name); + ini.addField(QString("effortValues-%1").arg(i), m_effortValues[i]); + ini.addField("growth", m_growth); + ini.addField("experienceValue", m_experienceValue); + ini.addField("catchValue", m_catchValue); + ini.addField("runChance-n", m_runChance.numerator()); + ini.addField("runChance-d", m_runChance.denominator()); + ini.addField("fleeChance-n", m_fleeChance.numerator()); + ini.addField("fleeChance-d", m_fleeChance.denominator()); + ini.addField("itemChance-n", m_itemChance.numerator()); + ini.addField("itemChance-d", m_itemChance.denominator()); + ini.addField("pokedexNumber", m_pokedexNumber); + ini.addField("weight", m_weight); + ini.addField("heightFeet", m_heightFeet); + ini.addField("heightInches", m_heightInches); + ini.addField("pokedexEntry", m_pokedexEntry); + ini.addField("genderFactor-n", m_genderFactor.numerator()); + ini.addField("genderFactor-d", m_genderFactor.denominator()); + ini.addField("eggSpecies", m_eggSpecies); + ini.addField("eggSteps", m_eggSteps); + ini.addField("nidoranGroup", m_nidoranGroup); + ini.addField("numTypes", m_types.size()); + for (int i = 0; i < m_types.size(); ++i) + ini.addField(QString("type-%1").arg(i), m_types[i]); + ini.addField("numEggGroups", m_eggGroups.size()); + for (int i = 0; i < m_eggGroups.size(); ++i) + ini.addField(QString("eggGroup-%1").arg(i), m_eggGroups[i]); + ini.save(QString("%1/species/%2/data.pini").arg(pokemod()->path()).arg(m_name)); + foreach (SpeciesAbility* ability, m_abilities) + ability->save(m_name); + foreach (SpeciesEvolution* evolution, m_evolutions) + evolution->save(m_name); + foreach (SpeciesItem* item, m_items) + item->save(m_name); + foreach (SpeciesMove* move, m_moves) + move->save(m_name); +} + +void Species::setName(const QString& name) +{ + m_name = name; +} + +void Species::setBaseStat(const int stat, const int base) throw(BoundsException) +{ + if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "stat")); + m_baseStats[stat] = base; +} + +void Species::setEffortValue(const int stat, const int effortPoints) throw(Exception) +{ + if (!pokemod()->rules()->effortValuesAllowed()) + throw(Exception(className(), "effortValues not allowed")); + if (pokemod()->rules()->maxEVPerStat() < effortPoints) + throw(BoundsException(className(), "effortValue")); + if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "stat")); + m_effortValues[stat] = effortPoints; +} + +void Species::setGrowth(const int growth) throw(BoundsException) +{ + if (End <= growth) + throw(BoundsException(className(), "growth")); + m_growth = growth; } -void Species::setName(const QString& n) +void Species::setExperienceValue(const int experienceValue) { - name = n; + m_experienceValue = experienceValue; } -void Species::setBaseStat(const int s, const int b) throw(BoundsException) +void Species::setCatchValue(const unsigned char catchValue) { - if ((Pokemod::ST_End_RBY <= s) || ((s == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "stat")); - baseStats[s] = b; + m_catchValue = catchValue; } -void Species::setEffortValue(const int s, const int e) throw(Exception) +void Species::setRunChance(const int numerator, const int denominator) throw(Exception) { - if (!pokemod->getRules()->getEffortValuesAllowed()) - throw(Exception(className, "effortValues not allowed")); - if (pokemod->getRules()->getMaxEVPerStat() < e) - throw(BoundsException(className, "effortValue")); - if ((Pokemod::ST_End_RBY <= s) || ((s == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "stat")); - effortValues[s] = e; + m_runChance.set(numerator, denominator); } -void Species::setGrowth(const int g) throw(BoundsException) +void Species::setFleeChance(const int numerator, const int denominator) throw(Exception) { - if (End <= g) - throw(BoundsException(className, "growth")); - growth = g; + m_fleeChance.set(numerator, denominator); } -void Species::setExperienceValue(const int e) +void Species::setItemChance(const int numerator, const int denominator) throw(Exception) { - experienceValue = e; + m_itemChance.set(numerator, denominator); } -void Species::setCatchValue(const unsigned char c) +void Species::setPokedexNumber(const int pokedexNumber) { - catchValue = c; + m_pokedexNumber = pokedexNumber; } -void Species::setRunChance(const int n, const int d) throw(Exception) +void Species::setWeight(const int weight) { - runChance.set(n, d); + m_weight = weight; } -void Species::setRunChanceNum(const int n) throw(Exception) +void Species::setHeightFeet(const int feet) { - runChance.setNum(n); + m_heightFeet = feet; } -void Species::setRunChanceDenom(const int d) throw(Exception) +void Species::setHeightInches(const int inches) throw(BoundsException) { - runChance.setDenom(d); + if (12 <= inches) + throw(BoundsException(className(), "heightInches")); + m_heightInches = inches; } -void Species::setFleeChance(const int n, const int d) throw(Exception) +void Species::setPokedexEntry(const QString& pokedexEntry) { - fleeChance.set(n, d); + m_pokedexEntry = pokedexEntry; } -void Species::setFleeChanceNum(const int n) throw(Exception) +void Species::setFrontMaleSprite(const QString& fileName) throw(Exception) { - fleeChance.setNum(n); + QFile file(frontMaleSprite()); + if (file.exists() && !file.remove()) + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, frontMaleSprite())) + throw(SaveException(className(), file.fileName())); } -void Species::setFleeChanceDenom(const int d) throw(Exception) +void Species::setBackMaleSprite(const QString& fileName) throw(Exception) { - fleeChance.setDenom(d); + QFile file(backMaleSprite()); + if (file.exists() && !file.remove()) + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, backMaleSprite())) + throw(SaveException(className(), file.fileName())); } -void Species::setItemChance(const int n, const int d) throw(Exception) +void Species::setFrontFemaleSprite(const QString& fileName) throw(Exception) { - itemChance.set(n, d); + if (!pokemod()->rules()->genderAllowed()) + throw(Exception(className(), "gender is not allowed")); + QFile file(frontFemaleSprite()); + if (file.exists() && !file.remove()) + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, frontFemaleSprite())) + throw(SaveException(className(), file.fileName())); } -void Species::setItemChanceNum(const int n) throw(Exception) +void Species::setBackFemaleSprite(const QString& fileName) throw(Exception) { - itemChance.setNum(n); + if (!pokemod()->rules()->genderAllowed()) + throw(Exception(className(), "gender is not allowed")); + QFile file(backFemaleSprite()); + if (file.exists() && !file.remove()) + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, backFemaleSprite())) + throw(SaveException(className(), file.fileName())); } -void Species::setItemChanceDenom(const int d) throw(Exception) +void Species::setListSprite(const QString& fileName) throw(Exception) { - itemChance.setDenom(d); + QFile file(listSprite()); + if (file.exists() && !file.remove()) + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, listSprite())) + throw(SaveException(className(), file.fileName())); } -void Species::setPokedexNumber(const int p) +void Species::setGenderFactor(const int numerator, const int denominator) throw(Exception) { - pokedexNumber = p; + m_genderFactor.set(numerator, denominator); } -void Species::setWeight(const int w) +void Species::setEggSpecies(const int eggSpecies) throw(BoundsException) { - weight = w; + if (pokemod()->speciesIndex(eggSpecies) == INT_MAX) + throw(BoundsException(className(), "eggSpecies")); + m_eggSpecies = eggSpecies; } -void Species::setHeightFeet(const int f) +void Species::setEggSteps(const int eggSteps) { - heightFeet = f; + m_eggSteps = eggSteps; } -void Species::setHeightInches(const int i) throw(BoundsException) +void Species::setNidoranGroup(const int nidoranGroup) { - if (12 <= i) - throw(BoundsException(className, "heightInches")); - heightInches = i; + m_nidoranGroup = nidoranGroup; } -void Species::setPokedexEntry(const QString& p) +void Species::setType(const int type, const bool state) throw(Exception) { - pokedexEntry = p; + if (pokemod()->typeIndex(type) == INT_MAX) + throw(BoundsException(className(), "type")); + if (state) + { + if (!m_types.contains(type)) + m_types.append(type); + } + else + m_types.removeAll(type); } -void Species::setFrontMaleSprite(const QString& fname) throw(Exception) +void Species::setEggGroup(const int eggGroup, const bool state) throw(Exception) { - QFile file(getFrontMaleSprite()); - if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getFrontMaleSprite())) - throw(SaveException(className, file.fileName())); + if (pokemod()->eggGroupIndex(eggGroup) == INT_MAX) + throw(BoundsException(className(), "eggGroup")); + if (state) + { + if (!m_types.contains(eggGroup)) + m_eggGroups.append(eggGroup); + } + else + m_eggGroups.removeAll(eggGroup); } -void Species::setBackMaleSprite(const QString& fname) throw(Exception) +QString Species::name() const { - QFile file(getBackMaleSprite()); - if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getBackMaleSprite())) - throw(SaveException(className, file.fileName())); + return m_name; } -void Species::setFrontFemaleSprite(const QString& fname) throw(Exception) +int Species::baseStat(const int stat) const throw(BoundsException) { - if (!pokemod->getRules()->getGenderAllowed()) - throw(Exception(className, "gender is not allowed")); - QFile file(getFrontFemaleSprite()); - if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getFrontFemaleSprite())) - throw(SaveException(className, file.fileName())); + if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "stat")); + return m_baseStats[stat]; } -void Species::setBackFemaleSprite(const QString& fname) throw(Exception) +int Species::effortValue(const int stat) const throw(BoundsException) { - if (!pokemod->getRules()->getGenderAllowed()) - throw(Exception(className, "gender is not allowed")); - QFile file(getBackFemaleSprite()); - if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getBackFemaleSprite())) - throw(SaveException(className, file.fileName())); + if ((Pokemod::ST_End_RBY <= stat) || ((stat == Pokemod::ST_SpecialDefense) && !pokemod()->rules()->specialSplit())) + throw(BoundsException(className(), "stat")); + return m_effortValues[stat]; } -void Species::setListSprite(const QString& fname) throw(Exception) +int Species::growth() const { - QFile file(getListSprite()); - if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getListSprite())) - throw(SaveException(className, file.fileName())); + return m_growth; } -void Species::setGenderFactor(const int n, const int d) throw(Exception) +int Species::experienceValue() const { - genderFactor.set(n, d); + return m_experienceValue; } -void Species::setGenderFactorNum(const int n) throw(Exception) +unsigned char Species::catchValue() const { - genderFactor.setNum(n); + return m_catchValue; } -void Species::setGenderFactorDenom(const int d) throw(Exception) +Frac Species::runChance() const { - genderFactor.setDenom(d); + return m_runChance; } -void Species::setEggSpecies(const int e) throw(BoundsException) +Frac Species::fleeChance() const { - if (pokemod->getSpeciesIndex(e) == -1) - throw(BoundsException(className, "eggSpecies")); - eggSpecies = e; + return m_fleeChance; } -void Species::setEggSteps(const int e) +Frac Species::itemChance() const { - eggSteps = e; + return m_itemChance; } -void Species::setNidoranGroup(const int n) +int Species::pokedexNumber() const { - nidoranGroup = n; + return m_pokedexNumber; } -void Species::setType(const int ty, const bool t) throw(Exception) +int Species::weight() const { - if (pokemod->getTypeIndex(ty) == -1) - throw(BoundsException(className, "type")); - for (QMutableListIterator<int> i(types); i.hasNext(); ) - { - if (i.next() == ty) - { - if (t) - throw(Exception(className, "type already used")); - else - i.remove(); - } - } - if (!t) - throw(Exception(className, "type wasn\'t being used anyway")); - types.append(ty); + return m_weight; } -void Species::setEggGroup(const int eg, const bool e) throw(Exception) +int Species::heightFeet() const { - if (pokemod->getEggGroupIndex(eg) == -1) - throw(BoundsException(className, "eggGroup")); - for (QMutableListIterator<int> i(eggGroups); i.hasNext(); ) - { - if (i.next() == eg) - { - if (e) - throw(Exception(className, "egg group already used")); - else - i.remove(); - } - } - if (!e) - throw(Exception(className, "egg group wasn\'t being used anyway")); - eggGroups.append(eg); + return m_heightFeet; } -QString Species::getName() const +int Species::heightInches() const { - return name; + return m_heightInches; } -int Species::getBaseStat(const int s) const throw(BoundsException) +QString Species::pokedexEntry() const { - if ((Pokemod::ST_End_RBY <= s) || ((s == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "stat")); - return baseStats[s]; + return m_pokedexEntry; } -int Species::getEffortValue(const int s) const throw(BoundsException) +QString Species::frontMaleSprite() const { - if ((Pokemod::ST_End_RBY <= s) || ((s == Pokemod::ST_SpecialDefense) && !pokemod->getRules()->getSpecialSplit())) - throw(BoundsException(className, "stat")); - return effortValues[s]; + return QString("%1/species/%2/front-male.png").arg(pokemod()->path()).arg(m_name); } -int Species::getGrowth() const +QString Species::backMaleSprite() const { - return growth; + return QString("%1/species/%2/back-male.png").arg(pokemod()->path()).arg(m_name); } -int Species::getExperienceValue() const +QString Species::frontFemaleSprite() const { - return experienceValue; + return QString("%1/species/%2/front-female.png").arg(pokemod()->path()).arg(m_name); } -unsigned char Species::getCatchValue() const +QString Species::backFemaleSprite() const { - return catchValue; + return QString("%1/species/%2/back-female.png").arg(pokemod()->path()).arg(m_name); } -Frac Species::getRunChance() const +QString Species::listSprite() const { - return runChance; + return QString("%1/species/%2/list.png").arg(pokemod()->path()).arg(m_name); } -Frac Species::getFleeChance() const +Frac Species::genderFactor() const { - return fleeChance; + return m_genderFactor; } -Frac Species::getItemChance() const +int Species::eggSpecies() const { - return itemChance; + return m_eggSpecies; } -int Species::getPokedexNumber() const +int Species::eggSteps() const { - return pokedexNumber; + return m_eggSteps; } -int Species::getWeight() const +int Species::nidoranGroup() const { - return weight; + return m_nidoranGroup; } -int Species::getHeightFeet() const +bool Species::type(const int type) const { - return heightFeet; + return m_types.contains(type); } -int Species::getHeightInches() const +bool Species::eggGroup(const int eggGroup) const { - return heightInches; + return m_eggGroups.contains(eggGroup); } -QString Species::getPokedexEntry() const +const SpeciesAbility* Species::ability(const int index) const throw(IndexException) { - return pokedexEntry; + if (abilityCount() <= index) + throw(IndexException(className())); + return m_abilities.at(index); } -QString Species::getFrontMaleSprite() const +SpeciesAbility* Species::ability(const int index) throw(IndexException) { - return QString("%1/species/%2/front-male.png").arg(pokemod->getPath()).arg(name); + if (abilityCount() <= index) + throw(IndexException(className())); + return m_abilities[index]; } -QString Species::getBackMaleSprite() const +const SpeciesAbility* Species::abilityById(const int id) const throw(IndexException) { - return QString("%1/species/%2/back-male.png").arg(pokemod->getPath()).arg(name); + return ability(abilityIndex(id)); } -QString Species::getFrontFemaleSprite() const +SpeciesAbility* Species::abilityById(const int id) throw(IndexException) { - return QString("%1/species/%2/front-female.png").arg(pokemod->getPath()).arg(name); + return ability(abilityIndex(id)); } -QString Species::getBackFemaleSprite() const +int Species::abilityIndex(const int id) const { - return QString("%1/species/%2/back-female.png").arg(pokemod->getPath()).arg(name); + for (int i = 0; i < abilityCount(); ++i) + { + if (m_abilities[i]->id() == id) + return i; + } + return INT_MAX; } -QString Species::getListSprite() const +int Species::abilityCount() const { - return QString("%1/species/%2/list.png").arg(pokemod->getPath()).arg(name); + return m_abilities.size(); } -Frac Species::getGenderFactor() const +SpeciesAbility* Species::newAbility() { - return genderFactor; + m_abilities.append(new SpeciesAbility(pokemod(), newAbilityId())); + return m_abilities[abilityCount() - 1]; } -int Species::getEggSpecies() const +SpeciesAbility* Species::newAbility(const QString& fileName) { - return eggSpecies; + m_abilities.append(new SpeciesAbility(pokemod(), fileName, newAbilityId())); + return m_abilities[abilityCount() - 1]; } -int Species::getEggSteps() const +SpeciesAbility* Species::newAbility(const SpeciesAbility& ability) { - return eggSteps; + m_abilities.append(new SpeciesAbility(pokemod(), ability, newAbilityId())); + return m_abilities[abilityCount() - 1]; } -int Species::getNidoranGroup() const +void Species::deleteAbility(const int index) throw(IndexException) { - return nidoranGroup; + if (abilityCount() <= index) + throw(IndexException(className())); + delete m_abilities[index]; + m_abilities.removeAt(index); } -bool Species::getType(const int ty) const +void Species::deleteAbilityById(const int id) throw(IndexException) { - for (QListIterator<int> i(types); i.hasNext(); ) - { - if (i.next() == ty) - return true; - } - return false; + deleteAbility(abilityIndex(id)); } -bool Species::getEggGroup(const int eg) const +int Species::newAbilityId() const { - for (QListIterator<int> i(eggGroups); i.hasNext(); ) - { - if (i.next() == eg) - return true; - } - return false; + int i = 0; + while ((i < abilityCount()) && (abilityIndex(i) != INT_MAX)) + ++i; + return i; } -const SpeciesAbility* Species::getAbility(const int i) const throw(IndexException) +const SpeciesEvolution* Species::evolution(const int index) const throw(IndexException) { - if (getAbilityCount() <= i) - throw(IndexException(className)); - return abilities.at(i); + if (evolutionCount() <= index) + throw(IndexException(className())); + return m_evolutions.at(index); } -SpeciesAbility* Species::getAbility(const int i) throw(IndexException) +SpeciesEvolution* Species::evolution(const int index) throw(IndexException) { - if (getAbilityCount() <= i) - throw(IndexException(className)); - return abilities[i]; + if (evolutionCount() <= index) + throw(IndexException(className())); + return m_evolutions[index]; } -const SpeciesAbility* Species::getAbilityByID(const int i) const throw(IndexException) +const SpeciesEvolution* Species::evolutionById(const int id) const throw(IndexException) { - return getAbility(getAbilityIndex(i)); + return evolution(evolutionIndex(id)); } -SpeciesAbility* Species::getAbilityByID(const int i) throw(IndexException) +SpeciesEvolution* Species::evolutionById(const int id) throw(IndexException) { - return getAbility(getAbilityIndex(i)); + return evolution(evolutionIndex(id)); } -int Species::getAbilityIndex(const int _id) const +int Species::evolutionIndex(const int id) const { - for (int i = 0; i < getAbilityCount(); ++i) + for (int i = 0; i < evolutionCount(); ++i) { - if (abilities[i]->getId() == _id) + if (m_evolutions[i]->id() == id) return i; } - return -1; -} - -int Species::getAbilityCount() const -{ - return abilities.size(); + return INT_MAX; } -SpeciesAbility* Species::newAbility() +int Species::evolutionCount() const { - abilities.append(new SpeciesAbility(pokemod, getNewAbilityId())); - return abilities[getAbilityCount() - 1]; + return m_evolutions.size(); } -SpeciesAbility* Species::newAbility(const QString& fname) -{ - abilities.append(new SpeciesAbility(pokemod, fname, getNewAbilityId())); - return abilities[getAbilityCount() - 1]; -} - -SpeciesAbility* Species::newAbility(const SpeciesAbility& a) -{ - abilities.append(new SpeciesAbility(pokemod, a, getNewAbilityId())); - return abilities[getAbilityCount() - 1]; -} - -void Species::deleteAbility(const int i) throw(IndexException) +SpeciesEvolution* Species::newEvolution() { - if (getAbilityCount() <= i) - throw(IndexException(className)); - delete abilities[i]; - abilities.removeAt(i); + m_evolutions.append(new SpeciesEvolution(pokemod(), newEvolutionId())); + return m_evolutions[evolutionCount() - 1]; } -const SpeciesEvolution* Species::getEvolution(const int i) const throw(IndexException) +SpeciesEvolution* Species::newEvolution(const QString& fileName) { - if (getEvolutionCount() <= i) - throw(IndexException(className)); - return evolutions.at(i); + m_evolutions.append(new SpeciesEvolution(pokemod(), fileName, newEvolutionId())); + return m_evolutions[evolutionCount() - 1]; } -SpeciesEvolution* Species::getEvolution(const int i) throw(IndexException) +SpeciesEvolution* Species::newEvolution(const SpeciesEvolution& evolution) { - if (getEvolutionCount() <= i) - throw(IndexException(className)); - return evolutions[i]; + m_evolutions.append(new SpeciesEvolution(pokemod(), evolution, newEvolutionId())); + return m_evolutions[evolutionCount() - 1]; } -const SpeciesEvolution* Species::getEvolutionByID(const int i) const throw(IndexException) +void Species::deleteEvolution(const int index) throw(IndexException) { - return getEvolution(getEvolutionIndex(i)); + if (evolutionCount() <= index) + throw(IndexException(className())); + delete m_evolutions[index]; + m_evolutions.removeAt(index); } -SpeciesEvolution* Species::getEvolutionByID(const int i) throw(IndexException) +void Species::deleteEvolutionById(const int id) throw(IndexException) { - return getEvolution(getEvolutionIndex(i)); + deleteEvolution(evolutionIndex(id)); } -int Species::getEvolutionIndex(const int _id) const +int Species::newEvolutionId() const { - for (int i = 0; i < getEvolutionCount(); ++i) - { - if (evolutions[i]->getId() == _id) - return i; - } - return -1; -} - -int Species::getEvolutionCount() const -{ - return evolutions.size(); + int i = 0; + while ((i < evolutionCount()) && (evolutionIndex(i) != INT_MAX)) + ++i; + return i; } -SpeciesEvolution* Species::newEvolution() +const SpeciesItem* Species::item(const int index) const throw(IndexException) { - evolutions.append(new SpeciesEvolution(pokemod, getNewEvolutionId())); - return evolutions[getEvolutionCount() - 1]; + if (itemCount() <= index) + throw(IndexException(className())); + return m_items.at(index); } -SpeciesEvolution* Species::newEvolution(const QString& fname) +SpeciesItem* Species::item(const int index) throw(IndexException) { - evolutions.append(new SpeciesEvolution(pokemod, fname, getNewEvolutionId())); - return evolutions[getEvolutionCount() - 1]; + if (itemCount() <= index) + throw(IndexException(className())); + return m_items[index]; } -SpeciesEvolution* Species::newEvolution(const SpeciesEvolution& e) +const SpeciesItem* Species::itemById(const int id) const throw(IndexException) { - evolutions.append(new SpeciesEvolution(pokemod, e, getNewEvolutionId())); - return evolutions[getEvolutionCount() - 1]; + return item(itemIndex(id)); } -void Species::deleteEvolution(const int i) throw(IndexException) +SpeciesItem* Species::itemById(const int id) throw(IndexException) { - if (getEvolutionCount() <= i) - throw(IndexException(className)); - delete evolutions[i]; - evolutions.removeAt(i); + return item(itemIndex(id)); } -const SpeciesItem* Species::getItem(const int i) const throw(IndexException) +int Species::itemIndex(const int id) const { - if (getItemCount() <= i) - throw(IndexException(className)); - return items.at(i); + for (int i = 0; i < itemCount(); ++i) + { + if (m_items[i]->id() == id) + return i; + } + return INT_MAX; } -SpeciesItem* Species::getItem(const int i) throw(IndexException) +int Species::itemCount() const { - if (getItemCount() <= i) - throw(IndexException(className)); - return items[i]; + return m_items.size(); } -const SpeciesItem* Species::getItemByID(const int i) const throw(IndexException) +SpeciesItem* Species::newItem() { - return getItem(getItemIndex(i)); + m_items.append(new SpeciesItem(pokemod(), newItemId())); + return m_items[itemCount() - 1]; } -SpeciesItem* Species::getItemByID(const int i) throw(IndexException) +SpeciesItem* Species::newItem(const QString& fileName) { - return getItem(getItemIndex(i)); + m_items.append(new SpeciesItem(pokemod(), fileName, newItemId())); + return m_items[itemCount() - 1]; } -int Species::getItemIndex(const int _id) const +SpeciesItem* Species::newItem(const SpeciesItem& item) { - for (int i = 0; i < getItemCount(); ++i) - { - if (items[i]->getId() == _id) - return i; - } - return -1; + m_items.append(new SpeciesItem(pokemod(), item, newItemId())); + return m_items[itemCount() - 1]; } -int Species::getItemCount() const +void Species::deleteItem(const int index) throw(IndexException) { - return items.size(); + if (itemCount() <= index) + throw(IndexException(className())); + delete m_items[index]; + m_items.removeAt(index); } -SpeciesItem* Species::newItem() +void Species::deleteItemById(const int id) throw(IndexException) { - items.append(new SpeciesItem(pokemod, getNewItemId())); - return items[getItemCount() - 1]; + deleteItem(itemIndex(id)); } -SpeciesItem* Species::newItem(const QString& fname) +int Species::newItemId() const { - items.append(new SpeciesItem(pokemod, fname, getNewItemId())); - return items[getItemCount() - 1]; + int i = 0; + while ((i < itemCount()) && (itemIndex(i) != INT_MAX)) + ++i; + return i; } -SpeciesItem* Species::newItem(const SpeciesItem& i) +const SpeciesMove* Species::move(const int index) const throw(IndexException) { - items.append(new SpeciesItem(pokemod, i, getNewItemId())); - return items[getItemCount() - 1]; + if (moveCount() <= index) + throw(IndexException(className())); + return m_moves.at(index); } -void Species::deleteItem(const int i) throw(IndexException) +SpeciesMove* Species::move(const int index) throw(IndexException) { - if (getItemCount() <= i) - throw(IndexException(className)); - delete items[i]; - items.removeAt(i); + if (moveCount() <= index) + throw(IndexException(className())); + return m_moves[index]; } -const SpeciesMove* Species::getMove(const int i) const throw(IndexException) +const SpeciesMove* Species::moveById(const int id) const throw(IndexException) { - if (getMoveCount() <= i) - throw(IndexException(className)); - return moves.at(i); + return move(moveIndex(id)); } -SpeciesMove* Species::getMove(const int i) throw(IndexException) +SpeciesMove* Species::moveById(const int id) throw(IndexException) { - if (getMoveCount() <= i) - throw(IndexException(className)); - return moves[i]; + return move(moveIndex(id)); } -const SpeciesMove* Species::getMoveByID(const int i) const throw(IndexException) +int Species::moveIndex(const int id) const { - return getMove(getMoveIndex(i)); + for (int i = 0; i < moveCount(); ++i) + { + if (m_moves[i]->id() == id) + return i; + } + return INT_MAX; } -SpeciesMove* Species::getMoveByID(const int i) throw(IndexException) +int Species::moveCount() const { - return getMove(getMoveIndex(i)); + return m_moves.size(); } -int Species::getMoveIndex(const int _id) const +SpeciesMove* Species::newMove() { - for (int i = 0; i < getMoveCount(); ++i) - { - if (moves[i]->getId() == _id) - return i; - } - return -1; + m_moves.append(new SpeciesMove(pokemod(), newMoveId())); + return m_moves[moveCount() - 1]; } -int Species::getMoveCount() const +SpeciesMove* Species::newMove(const QString& fileName) { - return moves.size(); + m_moves.append(new SpeciesMove(pokemod(), fileName, newMoveId())); + return m_moves[moveCount() - 1]; } -SpeciesMove* Species::newMove() +SpeciesMove* Species::newMove(const SpeciesMove& move) { - moves.append(new SpeciesMove(pokemod, getNewMoveId())); - return moves[getMoveCount() - 1]; + m_moves.append(new SpeciesMove(pokemod(), move, newMoveId())); + return m_moves[moveCount() - 1]; } -SpeciesMove* Species::newMove(const QString& fname) +void Species::deleteMove(const int index) throw(IndexException) { - moves.append(new SpeciesMove(pokemod, fname, getNewMoveId())); - return moves[getMoveCount() - 1]; + if (moveCount() <= index) + throw(IndexException(className())); + delete m_moves[index]; + m_moves.removeAt(index); } -SpeciesMove* Species::newMove(const SpeciesMove& m) +void Species::deleteMoveById(const int id) throw(IndexException) { - moves.append(new SpeciesMove(pokemod, m, getNewMoveId())); - return moves[getMoveCount() - 1]; + deleteMove(moveIndex(id)); } -void Species::deleteMove(const int i) throw(IndexException) +int Species::newMoveId() const { - if (getMoveCount() <= i) - throw(IndexException(className)); - delete moves[i]; - moves.removeAt(i); + int i = 0; + while ((i < moveCount()) && (moveIndex(i) != INT_MAX)) + ++i; + return i; } Species& Species::operator=(const Species& rhs) { if (this == &rhs) return *this; - name = rhs.name; + m_name = rhs.m_name; for (int i = 0; i < Pokemod::ST_End_GSC; ++i) { - baseStats[i] = rhs.baseStats[i]; - effortValues[i] = rhs.effortValues[i]; + m_baseStats[i] = rhs.m_baseStats[i]; + m_effortValues[i] = rhs.m_effortValues[i]; } - growth = rhs.growth; - experienceValue = rhs.experienceValue; - catchValue = rhs.catchValue; - runChance = rhs.runChance; - fleeChance = rhs.fleeChance; - itemChance = rhs.itemChance; - pokedexNumber = rhs.pokedexNumber; - weight = rhs.weight; - heightFeet = rhs.heightFeet; - heightInches = rhs.heightInches; - pokedexEntry = rhs.pokedexEntry; - genderFactor = rhs.genderFactor; - eggSpecies = rhs.eggSpecies; - eggSteps = rhs.eggSteps; - nidoranGroup = rhs.nidoranGroup; - types = rhs.types; - eggGroups = rhs.eggGroups; - abilities.clear(); - for (int i = 0; i < rhs.getAbilityCount(); ++i) - abilities.append(new SpeciesAbility(pokemod, *rhs.getAbility(i), rhs.getAbility(i)->getId())); - evolutions.clear(); - for (int i = 0; i < rhs.getEvolutionCount(); ++i) - evolutions.append(new SpeciesEvolution(pokemod, *rhs.getEvolution(i), rhs.getEvolution(i)->getId())); - items.clear(); - for (int i = 0; i < rhs.getItemCount(); ++i) - items.append(new SpeciesItem(pokemod, *rhs.getItem(i), rhs.getItem(i)->getId())); - moves.clear(); - for (int i = 0; i < rhs.getMoveCount(); ++i) - moves.append(new SpeciesMove(pokemod, *rhs.getMove(i), rhs.getMove(i)->getId())); + m_growth = rhs.m_growth; + m_experienceValue = rhs.m_experienceValue; + m_catchValue = rhs.m_catchValue; + m_runChance = rhs.m_runChance; + m_fleeChance = rhs.m_fleeChance; + m_itemChance = rhs.m_itemChance; + m_pokedexNumber = rhs.m_pokedexNumber; + m_weight = rhs.m_weight; + m_heightFeet = rhs.m_heightFeet; + m_heightInches = rhs.m_heightInches; + m_pokedexEntry = rhs.m_pokedexEntry; + m_genderFactor = rhs.m_genderFactor; + m_eggSpecies = rhs.m_eggSpecies; + m_eggSteps = rhs.m_eggSteps; + m_nidoranGroup = rhs.m_nidoranGroup; + m_types = rhs.m_types; + m_eggGroups = rhs.m_eggGroups; + m_abilities.clear(); + foreach (SpeciesAbility* ability, rhs.m_abilities) + m_abilities.append(new SpeciesAbility(pokemod(), *ability, ability->id())); + m_evolutions.clear(); + foreach (SpeciesEvolution* evolution, rhs.m_evolutions) + m_evolutions.append(new SpeciesEvolution(pokemod(), *evolution, evolution->id())); + m_items.clear(); + foreach (SpeciesItem* item, rhs.m_items) + m_items.append(new SpeciesItem(pokemod(), *item, item->id())); + m_moves.clear(); + foreach (SpeciesMove* move, rhs.m_moves) + m_moves.append(new SpeciesMove(pokemod(), *move, move->id())); return *this; } diff --git a/pokemod/Species.h b/pokemod/Species.h index bc426291..e843aea1 100644 --- a/pokemod/Species.h +++ b/pokemod/Species.h @@ -1,38 +1,37 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Species.h -// Purpose: Define a species -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:41:10 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" #include "Pokemod.h" +// Forward declarations class SpeciesAbility; class SpeciesEvolution; class SpeciesItem; @@ -53,151 +52,147 @@ class Species : public Object }; static const QStringList StyleStr; - Species(const Pokemod* par, const int _id); - Species(const Pokemod* par, const Species& s, const int _id); - Species(const Pokemod* par, const QString& fname, const int _id = -1); + Species(const Pokemod* pokemod, const int id); + Species(const Pokemod* pokemod, const Species& species, const int id); + Species(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); ~Species(); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setBaseStat(const int s, const int b) throw(BoundsException); - void setEffortValue(const int s, const int e) throw(Exception); - void setGrowth(const int g) throw(BoundsException); - void setExperienceValue(const int e); - void setCatchValue(const unsigned char c); - void setRunChance(const int n, const int d) throw(Exception); - void setRunChanceNum(const int n) throw(Exception); - void setRunChanceDenom(const int d) throw(Exception); - void setFleeChance(const int n, const int d) throw(Exception); - void setFleeChanceNum(const int n) throw(Exception); - void setFleeChanceDenom(const int d) throw(Exception); - void setItemChance(const int n, const int d) throw(Exception); - void setItemChanceNum(const int n) throw(Exception); - void setItemChanceDenom(const int d) throw(Exception); - void setPokedexNumber(const int p); - void setWeight(const int w); - void setHeightFeet(const int f); - void setHeightInches(const int i) throw(BoundsException); - void setPokedexEntry(const QString& p); - void setFrontMaleSprite(const QString& fname) throw(Exception); - void setBackMaleSprite(const QString& fname) throw(Exception); - void setFrontFemaleSprite(const QString& fname) throw(Exception); - void setBackFemaleSprite(const QString& fname) throw(Exception); - void setListSprite(const QString& fname) throw(Exception); - void setGenderFactor(const int n, const int d) throw(Exception); - void setGenderFactorNum(const int n) throw(Exception); - void setGenderFactorDenom(const int d) throw(Exception); - void setEggSpecies(const int e) throw(BoundsException); - void setEggSteps(const int e); - void setNidoranGroup(const int n); - void setType(const int ty, const bool t) throw(Exception); - void setEggGroup(const int eg, const bool e) throw(Exception); + void setName(const QString& name); + void setBaseStat(const int stat, const int base) throw(BoundsException); + void setEffortValue(const int stat, const int effectPoints) throw(Exception); + void setGrowth(const int growth) throw(BoundsException); + void setExperienceValue(const int experienceValue); + void setCatchValue(const unsigned char catchValue); + void setRunChance(const int numerator, const int denominator) throw(Exception); + void setFleeChance(const int numerator, const int denominator) throw(Exception); + void setItemChance(const int numerator, const int denominator) throw(Exception); + void setPokedexNumber(const int pokedexNumber); + void setWeight(const int weight); + void setHeightFeet(const int feet); + void setHeightInches(const int inches) throw(BoundsException); + void setPokedexEntry(const QString& pokedexEntry); + void setFrontMaleSprite(const QString& fileName) throw(Exception); + void setBackMaleSprite(const QString& fileName) throw(Exception); + void setFrontFemaleSprite(const QString& fileName) throw(Exception); + void setBackFemaleSprite(const QString& fileName) throw(Exception); + void setListSprite(const QString& fileName) throw(Exception); + void setGenderFactor(const int numerator, const int denominator) throw(Exception); + void setEggSpecies(const int eggSpecies) throw(BoundsException); + void setEggSteps(const int eggSteps); + void setNidoranGroup(const int nidoranGroup); + void setType(const int type, const bool state) throw(Exception); + void setEggGroup(const int eggGroup, const bool state) throw(Exception); - QString getName() const; - int getBaseStat(const int s) const throw(BoundsException); - int getEffortValue(const int s) const throw(BoundsException); - int getGrowth() const; - int getExperienceValue() const; - unsigned char getCatchValue() const; - Frac getRunChance() const; - Frac getFleeChance() const; - Frac getItemChance() const; - int getPokedexNumber() const; - int getWeight() const; - int getHeightFeet() const; - int getHeightInches() const; - QString getPokedexEntry() const; - QString getFrontMaleSprite() const; - QString getBackMaleSprite() const; - QString getFrontFemaleSprite() const; - QString getBackFemaleSprite() const; - QString getListSprite() const; - Frac getGenderFactor() const; - int getEggSpecies() const; - int getEggSteps() const; - int getNidoranGroup() const; - bool getType(const int ty) const; - bool getEggGroup(const int eg) const; + QString name() const; + int baseStat(const int stat) const throw(BoundsException); + int effortValue(const int stat) const throw(BoundsException); + int growth() const; + int experienceValue() const; + unsigned char catchValue() const; + Frac runChance() const; + Frac fleeChance() const; + Frac itemChance() const; + int pokedexNumber() const; + int weight() const; + int heightFeet() const; + int heightInches() const; + QString pokedexEntry() const; + QString frontMaleSprite() const; + QString backMaleSprite() const; + QString frontFemaleSprite() const; + QString backFemaleSprite() const; + QString listSprite() const; + Frac genderFactor() const; + int eggSpecies() const; + int eggSteps() const; + int nidoranGroup() const; + bool type(const int type) const; + bool eggGroup(const int eggGroup) const; - const SpeciesAbility* getAbility(const int i) const throw(IndexException); - SpeciesAbility* getAbility(const int i) throw(IndexException); - const SpeciesAbility* getAbilityByID(const int i) const throw(IndexException); - SpeciesAbility* getAbilityByID(const int i) throw(IndexException); - int getAbilityIndex(const int _id) const; - int getAbilityCount() const; + const SpeciesAbility* ability(const int index) const throw(IndexException); + SpeciesAbility* ability(const int index) throw(IndexException); + const SpeciesAbility* abilityById(const int id) const throw(IndexException); + SpeciesAbility* abilityById(const int id) throw(IndexException); + int abilityIndex(const int id) const; + int abilityCount() const; SpeciesAbility* newAbility(); - SpeciesAbility* newAbility(const QString& fname); - SpeciesAbility* newAbility(const SpeciesAbility& a); - void deleteAbility(const int i) throw(IndexException); + SpeciesAbility* newAbility(const QString& fileName); + SpeciesAbility* newAbility(const SpeciesAbility& ability); + void deleteAbility(const int index) throw(IndexException); + void deleteAbilityById(const int id) throw(IndexException); - const SpeciesEvolution* getEvolution(const int i) const throw(IndexException); - SpeciesEvolution* getEvolution(const int i) throw(IndexException); - const SpeciesEvolution* getEvolutionByID(const int i) const throw(IndexException); - SpeciesEvolution* getEvolutionByID(const int i) throw(IndexException); - int getEvolutionIndex(const int _id) const; - int getEvolutionCount() const; + const SpeciesEvolution* evolution(const int index) const throw(IndexException); + SpeciesEvolution* evolution(const int index) throw(IndexException); + const SpeciesEvolution* evolutionById(const int id) const throw(IndexException); + SpeciesEvolution* evolutionById(const int id) throw(IndexException); + int evolutionIndex(const int id) const; + int evolutionCount() const; SpeciesEvolution* newEvolution(); - SpeciesEvolution* newEvolution(const QString& fname); - SpeciesEvolution* newEvolution(const SpeciesEvolution& e); - void deleteEvolution(const int i) throw(IndexException); + SpeciesEvolution* newEvolution(const QString& fileName); + SpeciesEvolution* newEvolution(const SpeciesEvolution& evolution); + void deleteEvolution(const int index) throw(IndexException); + void deleteEvolutionById(const int id) throw(IndexException); - const SpeciesItem* getItem(const int i) const throw(IndexException); - SpeciesItem* getItem(const int i) throw(IndexException); - const SpeciesItem* getItemByID(const int i) const throw(IndexException); - SpeciesItem* getItemByID(const int i) throw(IndexException); - int getItemIndex(const int _id) const; - int getItemCount() const; + const SpeciesItem* item(const int index) const throw(IndexException); + SpeciesItem* item(const int index) throw(IndexException); + const SpeciesItem* itemById(const int i) const throw(IndexException); + SpeciesItem* itemById(const int i) throw(IndexException); + int itemIndex(const int id) const; + int itemCount() const; SpeciesItem* newItem(); - SpeciesItem* newItem(const QString& fname); - SpeciesItem* newItem(const SpeciesItem& i); - void deleteItem(const int i) throw(IndexException); + SpeciesItem* newItem(const QString& fileName); + SpeciesItem* newItem(const SpeciesItem& item); + void deleteItem(const int index) throw(IndexException); + void deleteItemById(const int id) throw(IndexException); - const SpeciesMove* getMove(const int i) const throw(IndexException); - SpeciesMove* getMove(const int i) throw(IndexException); - const SpeciesMove* getMoveByID(const int i) const throw(IndexException); - SpeciesMove* getMoveByID(const int i) throw(IndexException); - int getMoveIndex(const int _id) const; - int getMoveCount() const; + const SpeciesMove* move(const int index) const throw(IndexException); + SpeciesMove* move(const int index) throw(IndexException); + const SpeciesMove* moveById(const int id) const throw(IndexException); + SpeciesMove* moveById(const int id) throw(IndexException); + int moveIndex(const int id) const; + int moveCount() const; SpeciesMove* newMove(); - SpeciesMove* newMove(const QString& fname); - SpeciesMove* newMove(const SpeciesMove& m); - void deleteMove(const int i) throw(IndexException); + SpeciesMove* newMove(const QString& fileName); + SpeciesMove* newMove(const SpeciesMove& move); + void deleteMove(const int index) throw(IndexException); + void deleteMoveById(const int id) throw(IndexException); Species& operator=(const Species& rhs); private: bool validate() const; - int getNewAbilityId() const; - int getNewEvolutionId() const; - int getNewItemId() const; - int getNewMoveId() const; + int newAbilityId() const; + int newEvolutionId() const; + int newItemId() const; + int newMoveId() const; - QString name; - bool baseStats[Pokemod::ST_End_GSC]; - bool effortValues[Pokemod::ST_End_GSC]; - int growth; - int experienceValue; - unsigned char catchValue; - Frac runChance; - Frac fleeChance; - Frac itemChance; - int pokedexNumber; - int weight; - int heightFeet; - int heightInches; - QString pokedexEntry; - Frac genderFactor; - int eggSpecies; - int eggSteps; - int nidoranGroup; - QList<int> types; - QList<int> eggGroups; + QString m_name; + bool m_baseStats[Pokemod::ST_End_GSC]; + bool m_effortValues[Pokemod::ST_End_GSC]; + int m_growth; + int m_experienceValue; + unsigned char m_catchValue; + Frac m_runChance; + Frac m_fleeChance; + Frac m_itemChance; + int m_pokedexNumber; + int m_weight; + int m_heightFeet; + int m_heightInches; + QString m_pokedexEntry; + Frac m_genderFactor; + int m_eggSpecies; + int m_eggSteps; + int m_nidoranGroup; + QList<int> m_types; + QList<int> m_eggGroups; - QList<SpeciesAbility*> abilities; - QList<SpeciesEvolution*> evolutions; - QList<SpeciesItem*> items; - QList<SpeciesMove*> moves; + QList<SpeciesAbility*> m_abilities; + QList<SpeciesEvolution*> m_evolutions; + QList<SpeciesItem*> m_items; + QList<SpeciesMove*> m_moves; }; #endif diff --git a/pokemod/SpeciesAbility.cpp b/pokemod/SpeciesAbility.cpp index b4a0cfe5..fe698dea 100644 --- a/pokemod/SpeciesAbility.cpp +++ b/pokemod/SpeciesAbility.cpp @@ -1,113 +1,110 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesAbility.cpp -// Purpose: Define an ability that a species can have -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:39:17 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Pokemod includes #include "Pokemod.h" + +// Header include #include "SpeciesAbility.h" -SpeciesAbility::SpeciesAbility(const Pokemod* par, const int _id) : - Object("SpeciesAbility", par, _id), - ability(-1), - weight(1) +SpeciesAbility::SpeciesAbility(const Pokemod* pokemod, const int id) : + Object("SpeciesAbility", pokemod, id), + m_ability(INT_MAX), + m_weight(1) { } -SpeciesAbility::SpeciesAbility(const Pokemod* par, const SpeciesAbility& a, const int _id) : - Object("SpeciesAbility", par, _id) +SpeciesAbility::SpeciesAbility(const Pokemod* pokemod, const SpeciesAbility& ability, const int id) : + Object("SpeciesAbility", pokemod, id) { - *this = a; + *this = ability; } -SpeciesAbility::SpeciesAbility(const Pokemod* par, const QString& fname, const int _id) : - Object("SpeciesAbility", par, _id) +SpeciesAbility::SpeciesAbility(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("SpeciesAbility", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool SpeciesAbility::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Ability with id %1---").arg(id), Pokemod::V_Msg); - if (pokemod->getAbilityIndex(ability) == -1) + pokemod()->validationMsg(QString("------Ability with id %1---").arg(id()), Pokemod::V_Msg); + if (pokemod()->abilityIndex(m_ability) == INT_MAX) { - pokemod->validationMsg("Invalid ability"); + pokemod()->validationMsg("Invalid ability"); valid = false; } - if (!weight) + if (!m_weight) { - pokemod->validationMsg("Invalid weight"); + pokemod()->validationMsg("Invalid weight"); valid = false; } return valid; } -void SpeciesAbility::load(const QString& fname, const int _id) throw(Exception) +void SpeciesAbility::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("ability", ability); - ini.getValue("weight", weight, 1); + setId(id); + ini.getValue("ability", m_ability); + ini.getValue("weight", m_weight, 1); } void SpeciesAbility::save(const QString& species) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("ability", ability); - ini.addField("weight", weight); - ini.save(QString("%1/species/%2/ability/%3.pini").arg(pokemod->getPath()).arg(species).arg(id)); + ini.addField("id", id()); + ini.addField("ability", m_ability); + ini.addField("weight", m_weight); + ini.save(QString("%1/species/%2/ability/%3.pini").arg(pokemod()->path()).arg(species).arg(id())); } -void SpeciesAbility::setAbility(const int a) throw(BoundsException) +void SpeciesAbility::setAbility(const int ability) throw(BoundsException) { - if (pokemod->getAbilityIndex(a) == -1) - throw(BoundsException(className, "ability")); - ability = a; + if (pokemod()->abilityIndex(ability) == INT_MAX) + throw(BoundsException(className(), "ability")); + m_ability = ability; } -void SpeciesAbility::setWeight(const int w) throw(BoundsException) +void SpeciesAbility::setWeight(const int weight) throw(BoundsException) { - if (!w) - throw(BoundsException(className, "weight")); - weight = w; + if (!weight) + throw(BoundsException(className(), "weight")); + m_weight = weight; } -int SpeciesAbility::getAbility() const +int SpeciesAbility::ability() const { - return ability; + return m_ability; } -int SpeciesAbility::getWeight() const +int SpeciesAbility::weight() const { - return weight; + return m_weight; } SpeciesAbility& SpeciesAbility::operator=(const SpeciesAbility& rhs) { if (this == &rhs) return *this; - ability = rhs.ability; - weight = rhs.weight; + m_ability = rhs.m_ability; + m_weight = rhs.m_weight; return *this; } diff --git a/pokemod/SpeciesAbility.h b/pokemod/SpeciesAbility.h index f7443236..bb870b12 100644 --- a/pokemod/SpeciesAbility.h +++ b/pokemod/SpeciesAbility.h @@ -1,58 +1,57 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesAbility.h -// Purpose: Define an ability that a species can have -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:39:17 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// General includes class Pokemod; class SpeciesAbility : public Object { public: - SpeciesAbility(const Pokemod* par, const int _id); - SpeciesAbility(const Pokemod* par, const SpeciesAbility& a, const int _id); - SpeciesAbility(const Pokemod* par, const QString& fname, const int _id = -1); + SpeciesAbility(const Pokemod* pokemod, const int id); + SpeciesAbility(const Pokemod* pokemod, const SpeciesAbility& ability, const int id); + SpeciesAbility(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& species) const throw(Exception); - void setAbility(const int a) throw(BoundsException); - void setWeight(const int w) throw(BoundsException); + void setAbility(const int ability) throw(BoundsException); + void setWeight(const int weight) throw(BoundsException); - int getAbility() const; - int getWeight() const; + int ability() const; + int weight() const; SpeciesAbility& operator=(const SpeciesAbility& rhs); private: bool validate() const; - int ability; - int weight; + int m_ability; + int m_weight; }; #endif diff --git a/pokemod/SpeciesEvolution.cpp b/pokemod/SpeciesEvolution.cpp index bd251a88..9500b75e 100644 --- a/pokemod/SpeciesEvolution.cpp +++ b/pokemod/SpeciesEvolution.cpp @@ -1,270 +1,267 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesEvolution.cpp -// Purpose: Define an evolution that a species can go through -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:45:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Pokemod includes #include "Pokemod.h" #include "Item.h" #include "ItemEffect.h" + +// Header include #include "SpeciesEvolution.h" const QStringList SpeciesEvolution::StyleStr = QStringList() << "Level" << "Happiness" << "Stat" << "Item" << "Trade" << "TradeItem" << "Personality" << "Spare Slot"; const QStringList SpeciesEvolution::GiveHoldStr = QStringList() <<"Give" << "Hold"; -SpeciesEvolution::SpeciesEvolution(const Pokemod* par, const int _id) : - Object("SpeciesEvolution", par, _id), - species(-1), - style(-1), - val1(-1), - val2(-1), - val3(-1), - level(0) +SpeciesEvolution::SpeciesEvolution(const Pokemod* pokemod, const int id) : + Object("SpeciesEvolution", pokemod, id), + m_species(INT_MAX), + m_style(INT_MAX), + m_value1(INT_MAX), + m_value2(INT_MAX), + m_value3(INT_MAX), + m_level(0) { } -SpeciesEvolution::SpeciesEvolution(const Pokemod* par, const SpeciesEvolution& e, const int _id) : - Object("SpeciesEvolution", par, _id) +SpeciesEvolution::SpeciesEvolution(const Pokemod* pokemod, const SpeciesEvolution& evolution, const int id) : + Object("SpeciesEvolution", pokemod, id) { - *this = e; + *this = evolution; } -SpeciesEvolution::SpeciesEvolution(const Pokemod* par, const QString& fname, const int _id) : - Object("SpeciesEvolution", par, _id) +SpeciesEvolution::SpeciesEvolution(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("SpeciesEvolution", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool SpeciesEvolution::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Evolution with id %1---").arg(id), Pokemod::V_Msg); - if (pokemod->getSpeciesIndex(species) == -1) + pokemod()->validationMsg(QString("------Evolution with id %1---").arg(id()), Pokemod::V_Msg); + if (pokemod()->speciesIndex(m_species) == INT_MAX) { - pokemod->validationMsg("Invalid species"); + pokemod()->validationMsg("Invalid species"); valid = false; } - if (style < S_End) + if (m_style < S_End) { bool ok = true; - switch (style) + switch (m_style) { case S_Happiness: case S_Stat: case S_Personality: - if (Pokemod::REL_End <= val1) + if (Pokemod::REL_End <= m_value1) ok = false; break; case S_Item: case S_TradeItem: - if (pokemod->getItemIndex(val1) == -1) + if (pokemod()->itemIndex(m_value1) == INT_MAX) ok = false; else { - for (int i = 0; (i < pokemod->getItemByID(val1)->getEffectCount()) && !ok; ++i) - ok = (pokemod->getItemByID(val1)->getEffect(i)->getEffect() == ItemEffect::E_Evolution); + for (int i = 0; (i < pokemod()->itemById(m_value1)->effectCount()) && !ok; ++i) + ok = (pokemod()->itemById(m_value1)->effect(i)->effect() == ItemEffect::E_Evolution); } break; } if (!ok) { - pokemod->validationMsg("Invalid val1"); + pokemod()->validationMsg("Invalid m_value1"); valid = false; ok = true; } - switch (style) + switch (m_style) { case S_Stat: - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= val2) + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= m_value2) ok = false; case S_Item: - if ((G_End <= val2) || ((val2 == G_Hold) && !pokemod->getRules()->getHoldItems())) + if ((G_End <= m_value2) || ((m_value2 == G_Hold) && !pokemod()->rules()->holdItems())) ok = false; break; } if (!ok) { - pokemod->validationMsg("Invalid val2"); + pokemod()->validationMsg("Invalid m_value2"); valid = false; ok = true; } } else { - pokemod->validationMsg("Invalid style"); + pokemod()->validationMsg("Invalid style"); valid = false; } - if (pokemod->getRules()->getMaxLevel() <= level) + if (pokemod()->rules()->maxLevel() <= m_level) { - pokemod->validationMsg("Invalid level"); + pokemod()->validationMsg("Invalid level"); valid = false; } return valid; } -void SpeciesEvolution::load(const QString& fname, const int _id) throw(Exception) +void SpeciesEvolution::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("species", species); - ini.getValue("style", style); - ini.getValue("val1", val1); - ini.getValue("val2", val2); - ini.getValue("val3", val3); - ini.getValue("level", level, 0); + setId(id); + ini.getValue("species", m_species); + ini.getValue("style", m_style); + ini.getValue("value1", m_value1); + ini.getValue("value2", m_value2); + ini.getValue("value3", m_value3); + ini.getValue("level", m_level, 0); } void SpeciesEvolution::save(const QString& species) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("species", species); - ini.addField("style", style); - ini.addField("val1", val1); - ini.addField("val2", val2); - ini.addField("val3", val3); - ini.addField("level", level); - ini.save(QString("%1/species/%2/evolution/%3.pini").arg(pokemod->getPath()).arg(species).arg(id)); + ini.addField("id", id()); + ini.addField("species", m_species); + ini.addField("style", m_style); + ini.addField("value1", m_value1); + ini.addField("value2", m_value2); + ini.addField("value3", m_value3); + ini.addField("level", m_level); + ini.save(QString("%1/species/%2/evolution/%3.pini").arg(pokemod()->path()).arg(species).arg(id())); } -void SpeciesEvolution::setSpecies(const int s) throw(BoundsException) +void SpeciesEvolution::setSpecies(const int species) throw(BoundsException) { - if (pokemod->getSpeciesIndex(s) == -1) - throw(BoundsException(className, "species")); - species = s; + if (pokemod()->speciesIndex(species) == INT_MAX) + throw(BoundsException(className(), "species")); + m_species = species; } -void SpeciesEvolution::setStyle(const int s) throw(BoundsException) +void SpeciesEvolution::setStyle(const int style) throw(BoundsException) { - if (S_End <= s) - throw(BoundsException(className, "style")); - style = s; + if (S_End <= style) + throw(BoundsException(className(), "style")); + m_style = style; } -void SpeciesEvolution::setVal1(const int v1) throw(Exception) +void SpeciesEvolution::setValue1(const int value1) throw(Exception) { bool ok = false; - switch (style) + switch (m_style) { case S_Happiness: case S_Stat: case S_Personality: - if (Pokemod::REL_End <= v1) - throw(BoundsException(className, "val1")); + if (Pokemod::REL_End <= value1) + throw(BoundsException(className(), "value1")); break; case S_Item: case S_TradeItem: - if (pokemod->getItemIndex(v1) == -1) - throw(BoundsException(className, "val1")); - for (int i = 0; (i < pokemod->getItemByID(v1)->getEffectCount()) && !ok; ++i) - ok = (pokemod->getItemByID(v1)->getEffect(i)->getEffect() == ItemEffect::E_Evolution); + if (pokemod()->itemIndex(value1) == INT_MAX) + throw(BoundsException(className(), "value1")); + for (int i = 0; (i < pokemod()->itemById(value1)->effectCount()) && !ok; ++i) + ok = (pokemod()->itemById(value1)->effect(i)->effect() == ItemEffect::E_Evolution); if (!ok) - throw(BoundsException(className, "val1")); + throw(BoundsException(className(), "value1")); break; default: - throw(UnusedException(className, "val1")); + throw(UnusedException(className(), "value1")); break; } - val1 = v1; + m_value1 = value1; } -void SpeciesEvolution::setVal2(const int v2) throw(Exception) +void SpeciesEvolution::setValue2(const int value2) throw(Exception) { - switch (style) + switch (m_style) { case S_Stat: - if ((pokemod->getRules()->getSpecialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= v2) - throw(BoundsException(className, "val2")); + if ((pokemod()->rules()->specialSplit() ? Pokemod::ST_End_GSC : Pokemod::ST_End_RBY) <= value2) + throw(BoundsException(className(), "value2")); case S_Item: - if ((G_End <= v2) || ((v2 == G_Hold) && !pokemod->getRules()->getHoldItems())) - throw(BoundsException(className, "val2")); + if ((G_End <= value2) || ((value2 == G_Hold) && !pokemod()->rules()->holdItems())) + throw(BoundsException(className(), "value2")); break; default: - throw(UnusedException(className, "val2")); + throw(UnusedException(className(), "value2")); break; } - val2 = v2; + m_value2 = value2; } -void SpeciesEvolution::setVal3(const int v3) throw(UnusedException) +void SpeciesEvolution::setValue3(const int value3) throw(UnusedException) { - switch (style) + switch (m_style) { case S_Happiness: case S_Stat: case S_Personality: break; default: - throw(UnusedException(className, "val3")); + throw(UnusedException(className(), "value3")); break; } - val3 = v3; + m_value3 = value3; } -void SpeciesEvolution::setLevel(const int l) throw(BoundsException) +void SpeciesEvolution::setLevel(const int level) throw(BoundsException) { - if (pokemod->getRules()->getMaxLevel() < l) - throw(BoundsException(className, "level")); - level = l; + if (pokemod()->rules()->maxLevel() < level) + throw(BoundsException(className(), "level")); + m_level = level; } -int SpeciesEvolution::getSpecies() const +int SpeciesEvolution::species() const { - return species; + return m_species; } -int SpeciesEvolution::getStyle() const +int SpeciesEvolution::style() const { - return style; + return m_style; } -int SpeciesEvolution::getVal1() const +int SpeciesEvolution::value1() const { - return val1; + return m_value1; } -int SpeciesEvolution::getVal2() const +int SpeciesEvolution::value2() const { - return val2; + return m_value2; } -int SpeciesEvolution::getVal3() const +int SpeciesEvolution::value3() const { - return val3; + return m_value3; } -int SpeciesEvolution::getLevel() const +int SpeciesEvolution::level() const { - return level; + return m_level; } SpeciesEvolution& SpeciesEvolution::operator=(const SpeciesEvolution& rhs) { if (this == &rhs) return *this; - species = rhs.species; - style = rhs.style; - val1 = rhs.val1; - val2 = rhs.val3; - level = rhs.level; + m_species = rhs.m_species; + m_style = rhs.m_style; + m_value1 = rhs.m_value1; + m_value2 = rhs.m_value3; + m_level = rhs.m_level; return *this; } diff --git a/pokemod/SpeciesEvolution.h b/pokemod/SpeciesEvolution.h index f70186df..329c3501 100644 --- a/pokemod/SpeciesEvolution.h +++ b/pokemod/SpeciesEvolution.h @@ -1,35 +1,34 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesEvolution.h -// Purpose: Define an evolution that a species can go through -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:45:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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_SPECIESEVOLUTION__ #define __POKEMOD_SPECIESEVOLUTION__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class SpeciesEvolution : public Object @@ -57,37 +56,37 @@ class SpeciesEvolution : public Object }; static const QStringList GiveHoldStr; - SpeciesEvolution(const Pokemod* par, const int _id); - SpeciesEvolution(const Pokemod* par, const SpeciesEvolution& e, const int _id); - SpeciesEvolution(const Pokemod* par, const QString& fname, const int _id = -1); + SpeciesEvolution(const Pokemod* pokemod, const int id); + SpeciesEvolution(const Pokemod* pokemod, const SpeciesEvolution& evolution, const int id); + SpeciesEvolution(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& species) const throw(Exception); - void setSpecies(const int s) throw(BoundsException); - void setStyle(const int s) throw(BoundsException); - void setVal1(const int v1) throw(Exception); - void setVal2(const int v2) throw(Exception); - void setVal3(const int v3) throw(UnusedException); - void setLevel(const int l) throw(BoundsException); + void setSpecies(const int species) throw(BoundsException); + void setStyle(const int style) throw(BoundsException); + void setValue1(const int value1) throw(Exception); + void setValue2(const int value2) throw(Exception); + void setValue3(const int value3) throw(UnusedException); + void setLevel(const int level) throw(BoundsException); - int getSpecies() const; - int getStyle() const; - int getVal1() const; - int getVal2() const; - int getVal3() const; - int getLevel() const; + int species() const; + int style() const; + int value1() const; + int value2() const; + int value3() const; + int level() const; SpeciesEvolution& operator=(const SpeciesEvolution& rhs); private: bool validate() const; - int species; - int style; - int val1; - int val2; - int val3; - int level; + int m_species; + int m_style; + int m_value1; + int m_value2; + int m_value3; + int m_level; }; #endif diff --git a/pokemod/SpeciesItem.cpp b/pokemod/SpeciesItem.cpp index 7946f661..51c782dc 100644 --- a/pokemod/SpeciesItem.cpp +++ b/pokemod/SpeciesItem.cpp @@ -1,113 +1,110 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesItem.cpp -// Purpose: Define an item that a species can be found with in the wild -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:40:28 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Pokemod includes #include "Pokemod.h" + +// Header include #include "SpeciesItem.h" -SpeciesItem::SpeciesItem(const Pokemod* par, const int _id) : - Object("SpeciesItem", par, _id), - item(-1), - weight(1) +SpeciesItem::SpeciesItem(const Pokemod* pokemod, const int id) : + Object("SpeciesItem", pokemod, id), + m_item(INT_MAX), + m_weight(1) { } -SpeciesItem::SpeciesItem(const Pokemod* par, const SpeciesItem& i, const int _id) : - Object("SpeciesItem", par, _id) +SpeciesItem::SpeciesItem(const Pokemod* pokemod, const SpeciesItem& item, const int id) : + Object("SpeciesItem", pokemod, id) { - *this = i; + *this = item; } -SpeciesItem::SpeciesItem(const Pokemod* par, const QString& fname, const int _id) : - Object("SpeciesItem", par, _id) +SpeciesItem::SpeciesItem(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("SpeciesItem", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool SpeciesItem::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Item with id %1---").arg(id), Pokemod::V_Msg); - if (pokemod->getItemIndex(item) == -1) + pokemod()->validationMsg(QString("------Item with id %1---").arg(id()), Pokemod::V_Msg); + if (pokemod()->itemIndex(m_item) == INT_MAX) { - pokemod->validationMsg("Invalid item"); + pokemod()->validationMsg("Invalid item"); valid = false; } - if (!weight) + if (!m_weight) { - pokemod->validationMsg("Invalid weight"); + pokemod()->validationMsg("Invalid weight"); valid = false; } return valid; } -void SpeciesItem::load(const QString& fname, const int _id) throw(Exception) +void SpeciesItem::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("item", item); - ini.getValue("weight", weight, 1); + setId(id); + ini.getValue("item", m_item); + ini.getValue("weight", m_weight, 1); } void SpeciesItem::save(const QString& species) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("item", item); - ini.addField("weight", weight); - ini.save(QString("%1/species/%2/item/%3.pini").arg(pokemod->getPath()).arg(species).arg(id)); + ini.addField("id", id()); + ini.addField("item", m_item); + ini.addField("weight", m_weight); + ini.save(QString("%1/species/%2/item/%3.pini").arg(pokemod()->path()).arg(species).arg(id())); } -void SpeciesItem::setItem(const int i) throw(BoundsException) +void SpeciesItem::setItem(const int item) throw(BoundsException) { - if (pokemod->getItemIndex(i) == -1) - throw(BoundsException(className, "item")); - item = i; + if (pokemod()->itemIndex(item) == INT_MAX) + throw(BoundsException(className(), "item")); + m_item = item; } -void SpeciesItem::setWeight(const int w) throw(BoundsException) +void SpeciesItem::setWeight(const int weight) throw(BoundsException) { - if (!w) - throw(BoundsException(className, "weight")); - weight = w; + if (!weight) + throw(BoundsException(className(), "weight")); + m_weight = weight; } -int SpeciesItem::getItem() const +int SpeciesItem::item() const { - return item; + return m_item; } -int SpeciesItem::getWeight() const +int SpeciesItem::weight() const { - return weight; + return m_weight; } SpeciesItem& SpeciesItem::operator=(const SpeciesItem& rhs) { if (this == &rhs) return *this; - item = rhs.item; - weight = rhs.weight; + m_item = rhs.m_item; + m_weight = rhs.m_weight; return *this; } diff --git a/pokemod/SpeciesItem.h b/pokemod/SpeciesItem.h index 31894276..358d6247 100644 --- a/pokemod/SpeciesItem.h +++ b/pokemod/SpeciesItem.h @@ -1,58 +1,57 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesItem.h -// Purpose: Define an item that a species can be found with in the wild -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:40:28 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class SpeciesItem : public Object { public: - SpeciesItem(const Pokemod* par, const int _id); - SpeciesItem(const Pokemod* par, const SpeciesItem& i, const int _id); - SpeciesItem(const Pokemod* par, const QString& fname, const int _id = -1); + SpeciesItem(const Pokemod* pokemod, const int id); + SpeciesItem(const Pokemod* pokemod, const SpeciesItem& item, const int id); + SpeciesItem(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& species) const throw(Exception); - void setItem(const int i) throw(BoundsException); - void setWeight(const int w) throw(BoundsException); + void setItem(const int item) throw(BoundsException); + void setWeight(const int weight) throw(BoundsException); - int getItem() const; - int getWeight() const; + int item() const; + int weight() const; SpeciesItem& operator=(const SpeciesItem& rhs); private: bool validate() const; - int item; - int weight; + int m_item; + int m_weight; }; #endif diff --git a/pokemod/SpeciesMove.cpp b/pokemod/SpeciesMove.cpp index 9ee4e189..9f3cd9d2 100644 --- a/pokemod/SpeciesMove.cpp +++ b/pokemod/SpeciesMove.cpp @@ -1,134 +1,131 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesMove.cpp -// Purpose: Define a move that a species can learn -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:45:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Pokemod includes #include "Pokemod.h" + +// Header include #include "SpeciesMove.h" -SpeciesMove::SpeciesMove(const Pokemod* par, const int _id) : - Object("SpeciesMove", par, _id), - move(-1), - level(0), - wild(0) +SpeciesMove::SpeciesMove(const Pokemod* pokemod, const int id) : + Object("SpeciesMove", pokemod, id), + m_move(INT_MAX), + m_level(0), + m_wild(0) { } -SpeciesMove::SpeciesMove(const Pokemod* par, const SpeciesMove& m, const int _id) : - Object("SpeciesMove", par, _id) +SpeciesMove::SpeciesMove(const Pokemod* pokemod, const SpeciesMove& move, const int id) : + Object("SpeciesMove", pokemod, id) { - *this = m; + *this = move; } -SpeciesMove::SpeciesMove(const Pokemod* par, const QString& fname, const int _id) : - Object("SpeciesMove", par, _id) +SpeciesMove::SpeciesMove(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("SpeciesMove", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool SpeciesMove::validate() const { bool valid = true; - pokemod->validationMsg(QString("------Move with id %1---").arg(id), Pokemod::V_Msg); - if (pokemod->getMoveIndex(move) == -1) + pokemod()->validationMsg(QString("------Move with id %1---").arg(id()), Pokemod::V_Msg); + if (pokemod()->moveIndex(m_move) == INT_MAX) { - pokemod->validationMsg("Invalid move"); + pokemod()->validationMsg("Invalid move"); valid = false; } - if (level < pokemod->getRules()->getMaxLevel()) + if (m_level < pokemod()->rules()->maxLevel()) { - pokemod->validationMsg("Invalid level"); + pokemod()->validationMsg("Invalid level"); valid = false; } - if (wild < pokemod->getRules()->getMaxLevel()) + if (m_wild < pokemod()->rules()->maxLevel()) { - pokemod->validationMsg("Invalid wild level"); + pokemod()->validationMsg("Invalid wild level"); valid = false; } return valid; } -void SpeciesMove::load(const QString& fname, const int _id) throw(Exception) +void SpeciesMove::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("move", move); - ini.getValue("level", level, 0); - ini.getValue("wild", wild, 0); + setId(id); + ini.getValue("move", m_move); + ini.getValue("level", m_level, 0); + ini.getValue("wild", m_wild, 0); } void SpeciesMove::save(const QString& species) const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("move", move); - ini.addField("level", level); - ini.addField("wild", wild); - ini.save(QString("%1/species/%2/move/%3.pini").arg(pokemod->getPath()).arg(species).arg(id)); + ini.addField("id", id()); + ini.addField("move", m_move); + ini.addField("level", m_level); + ini.addField("wild", m_wild); + ini.save(QString("%1/species/%2/move/%3.pini").arg(pokemod()->path()).arg(species).arg(id())); } -void SpeciesMove::setMove(const int m) throw(BoundsException) +void SpeciesMove::setMove(const int move) throw(BoundsException) { - if (pokemod->getMoveIndex(m) == -1) - throw(BoundsException(className, "move")); - move = m; + if (pokemod()->moveIndex(move) == INT_MAX) + throw(BoundsException(className(), "move")); + m_move = move; } -void SpeciesMove::setLevel(const int l) throw(BoundsException) +void SpeciesMove::setLevel(const int level) throw(BoundsException) { - if (pokemod->getRules()->getMaxLevel() <= l) - throw(BoundsException(className, "level")); - level = l; + if (pokemod()->rules()->maxLevel() <= level) + throw(BoundsException(className(), "level")); + m_level = level; } -void SpeciesMove::setWild(const int w) throw(BoundsException) +void SpeciesMove::setWild(const int wild) throw(BoundsException) { - if (pokemod->getRules()->getMaxLevel() <= w) - throw(BoundsException(className, "wild")); - wild = w; + if (pokemod()->rules()->maxLevel() <= wild) + throw(BoundsException(className(), "wild")); + m_wild = wild; } -int SpeciesMove::getMove() const +int SpeciesMove::move() const { - return move; + return m_move; } -int SpeciesMove::getLevel() const +int SpeciesMove::level() const { - return level; + return m_level; } -int SpeciesMove::getWild() const +int SpeciesMove::wild() const { - return wild; + return m_wild; } SpeciesMove& SpeciesMove::operator=(const SpeciesMove& rhs) { if (this == &rhs) return *this; - move = rhs.move; - level = rhs.level; - wild = rhs.wild; + m_move = rhs.m_move; + m_level = rhs.m_level; + m_wild = rhs.m_wild; return *this; } diff --git a/pokemod/SpeciesMove.h b/pokemod/SpeciesMove.h index 9e4ce078..5d95ff47 100644 --- a/pokemod/SpeciesMove.h +++ b/pokemod/SpeciesMove.h @@ -1,61 +1,60 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/SpeciesMove.h -// Purpose: Define a move that a species can learn -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:45:29 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class SpeciesMove : public Object { public: - SpeciesMove(const Pokemod* par, const int _id); - SpeciesMove(const Pokemod* par, const SpeciesMove& m, const int _id); - SpeciesMove(const Pokemod* par, const QString& fname, const int _id = -1); + SpeciesMove(const Pokemod* pokemod, const int id); + SpeciesMove(const Pokemod* pokemod, const SpeciesMove& move, const int id); + SpeciesMove(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save(const QString& species) const throw(Exception); - void setMove(const int m) throw(BoundsException); - void setLevel(const int l) throw(BoundsException); - void setWild(const int w) throw(BoundsException); + void setMove(const int move) throw(BoundsException); + void setLevel(const int level) throw(BoundsException); + void setWild(const int wild) throw(BoundsException); - int getMove() const; - int getLevel() const; - int getWild() const; + int move() const; + int level() const; + int wild() const; SpeciesMove& operator=(const SpeciesMove& rhs); private: bool validate() const; - int move; - int level; - int wild; + int m_move; + int m_level; + int m_wild; }; #endif diff --git a/pokemod/Store.cpp b/pokemod/Store.cpp index f715ef9b..94def03a 100644 --- a/pokemod/Store.cpp +++ b/pokemod/Store.cpp @@ -1,157 +1,139 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Store.cpp -// Purpose: Define a store that the player can shop at -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:31:50 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ -#include <QListIterator> +// Qt includes #include <QMap> -#include <QMapIterator> +// Pokemod includes #include "Pokemod.h" + +// Header include #include "Store.h" -Store::Store(const Pokemod* par, const int _id) : - Object("Store", par, _id), - name("") +Store::Store(const Pokemod* pokemod, const int id) : + Object("Store", pokemod, id), + m_name("") { } -Store::Store(const Pokemod* par, const Store& s, const int _id) : - Object("Store", par, _id) +Store::Store(const Pokemod* pokemod, const Store& store, const int id) : + Object("Store", pokemod, id) { - *this = s; + *this = store; } -Store::Store(const Pokemod* par, const QString& fname, const int _id) : - Object("Store", par, _id) +Store::Store(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Store", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Store::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Store \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Store \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is noe defiend"); + pokemod()->validationMsg("Name is noe defiend"); valid = false; } - if (!items.size()) + if (!m_items.size()) { - pokemod->validationMsg("There are no items"); + pokemod()->validationMsg("There are no items"); valid = false; } - QMap<int, int> nameChecker; - for (QListIterator<int> i(items); i.hasNext(); i.next()) - { - if (pokemod->getItemIndex(i.peekNext()) == -1) - { - pokemod->validationMsg("Invalid item"); - valid = false; - } - ++nameChecker[i.peekNext()]; - } - for (QMapIterator<int, int> i(nameChecker); i.hasNext(); i.next()) + QMap<int, bool> valueChecker; + foreach (int item, m_items) { - if (1 < i.value()) + if (pokemod()->itemIndex(item) == INT_MAX) { - pokemod->validationMsg(QString("There are %1 of item %2").arg(i.value()).arg(i.key())); + pokemod()->validationMsg("Invalid item"); valid = false; } + if (valueChecker[item]) + pokemod()->validationMsg(QString("Duplicate of item %1").arg(item)); + valueChecker[item] = true; } return valid; } -void Store::load(const QString& fname, const int _id) throw(Exception) +void Store::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - items.clear(); + setId(id); + m_items.clear(); int i; int j; - ini.getValue("name", name); + ini.getValue("name", m_name); ini.getValue("numItems", i, 0); for (int k = 0; k < i; ++k) { - ini.getValue(QString("item-%1").arg(k), j, -1); - if (j != -1) - items.append(j); + ini.getValue(QString("item-%1").arg(k), j); + if (!m_items.contains(j)) + m_items.append(j); } } void Store::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("numItems", items.size()); - for (int i = 0; i < items.size(); ++i) - ini.addField(QString("items-%1").arg(i), items[i]); - ini.save(QString("%1/store/%2.pini").arg(pokemod->getPath()).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("numItems", m_items.size()); + for (int i = 0; i < m_items.size(); ++i) + ini.addField(QString("items-%1").arg(i), m_items[i]); + ini.save(QString("%1/store/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Store::setName(const QString& n) +void Store::setName(const QString& name) { - name = n; + m_name = name; } -void Store::setItem(const int itm, const bool it) throw(Exception) +void Store::setItem(const int item, const bool state) throw(BoundsException) { - if (pokemod->getItemIndex(itm) == -1) - throw(BoundsException(className, "item")); - for (QMutableListIterator<int> i(items); i.hasNext(); ) + if (pokemod()->itemIndex(item) == INT_MAX) + throw(BoundsException(className(), "item")); + if (state) { - if (i.next() == itm) - { - if (!it) - i.remove(); - return; - } + if (!m_items.contains(item)) + m_items.append(item); } - items.append(itm); + else + m_items.removeAll(item); } -QString Store::getName() const +QString Store::name() const { - return name; + return m_name; } -bool Store::getItem(const int itm) const +bool Store::item(const int item) const { - for (QListIterator<int> i(items); i.hasNext(); ) - { - if (i.next() == itm) - return true; - } - return false; + return m_items.contains(item); } Store& Store::operator=(const Store& rhs) { if (this == &rhs) return *this; - name = rhs.name; - items = rhs.items; + m_name = rhs.m_name; + m_items = rhs.m_items; return *this; } diff --git a/pokemod/Store.h b/pokemod/Store.h index 70fb5ac3..76086cd1 100644 --- a/pokemod/Store.h +++ b/pokemod/Store.h @@ -1,59 +1,58 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Store.h -// Purpose: Define a store that the player can shop at -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:31:50 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QList> #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class Store : public Object { public: - Store(const Pokemod* par, const int _id); - Store(const Pokemod* par, const Store& s, const int _id); - Store(const Pokemod* par, const QString& fname, const int _id = -1); + Store(const Pokemod* pokemod, const int id); + Store(const Pokemod* pokemod, const Store& store, const int id); + Store(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setItem(const int itm, const bool it) throw(Exception); + void setName(const QString& name); + void setItem(const int item, const bool state) throw(BoundsException); - QString getName() const; - bool getItem(const int itm) const; + QString name() const; + bool item(const int item) const; Store& operator=(const Store& rhs); private: bool validate() const; - QString name; - QList<int> items; + QString m_name; + QList<int> m_items; }; #endif diff --git a/pokemod/TODO b/pokemod/TODO index 3a4dfbbe..b455b73c 100644 --- a/pokemod/TODO +++ b/pokemod/TODO @@ -1,3 +1,8 @@ MoveEffects (Validation, GSC+)
+General cleanup
+Qt signal/slot-ify
+get rid of exceptions
+
+in opeartor= and load, lists of subclasses leaks memory
Figure out what makes 2 PokéMods incompatable
diff --git a/pokemod/Tile.cpp b/pokemod/Tile.cpp index 2ef974b8..0c7a8195 100644 --- a/pokemod/Tile.cpp +++ b/pokemod/Tile.cpp @@ -1,274 +1,261 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Tile.cpp -// Purpose: Define a tile for the map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Thu May 31 2007 13:52:39 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Pokemod includes #include "Pokemod.h" + +// Header include #include "Tile.h" const QStringList Tile::ForceStr = QStringList() << "Slip" << "Stop" << "Force" << "Push"; -Tile::Tile(const Pokemod* par, const int _id) : - Object("Tile", par, _id), - name(""), - wildChance(1, 1), - hmType(-1), - under(-1), - forceType(-1), - forceDirection(-1) +Tile::Tile(const Pokemod* pokemod, const int id) : + Object("Tile", pokemod, id), + m_name(""), + m_wildChance(1, 1), + m_hmType(INT_MAX), + m_under(INT_MAX), + m_forceType(INT_MAX), + m_forceDirection(INT_MAX) { for (int i = 0; i < Pokemod::D_End; ++i) - from[i] = false; + m_from[i] = false; } -Tile::Tile(const Pokemod* par, const Tile& t, const int _id) : - Object("Tile", par, _id) +Tile::Tile(const Pokemod* pokemod, const Tile& tile, const int id) : + Object("Tile", pokemod, id) { - *this = t; + *this = tile; } -Tile::Tile(const Pokemod* par, const QString& fname, const int _id) : - Object("Tile", par, _id) +Tile::Tile(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Tile", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Tile::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Tile \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Tile \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name is not defined"); + pokemod()->validationMsg("Name is not defined"); valid = false; } - if (!QFile::exists(getPic())) + if (!QFile::exists(pic())) { - pokemod->validationMsg("Cannot find tile image"); + pokemod()->validationMsg("Cannot find tile image"); valid = false; } - if ((hmType == Pokemod::HM_Waterfall) && (!from[Pokemod::D_Up] || !from[Pokemod::D_Down])) + if ((m_hmType == Pokemod::HM_Waterfall) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) { - pokemod->validationMsg("A waterfall tile must be accessible from above and below"); + pokemod()->validationMsg("A waterfall tile must be accessible from above and below"); valid = false; } - else if ((hmType == Pokemod::HM_Whirlpool) && ((under == id) || (pokemod->getTileIndex(under) == -1) || (pokemod->getTileByID(under)->getHMType() != Pokemod::HM_Surf) || (pokemod->getTileByID(under)->getHMType() != Pokemod::HM_Dive))) + else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (pokemod()->tileIndex(m_under) == INT_MAX) || (pokemod()->tileById(m_under)->hmType() != Pokemod::HM_Surf) || (pokemod()->tileById(m_under)->hmType() != Pokemod::HM_Dive))) { - pokemod->validationMsg("Invalid under tile"); + pokemod()->validationMsg("Invalid under tile"); valid = false; } - else if ((hmType == Pokemod::HM_Whirlpool) && ((under == id) || (pokemod->getTileIndex(under) == -1) || (pokemod->getTileByID(under)->getHMType() != Pokemod::HM_End))) + else if ((m_hmType == Pokemod::HM_Whirlpool) && ((m_under == id()) || (pokemod()->tileIndex(m_under) == INT_MAX) || (pokemod()->tileById(m_under)->hmType() != Pokemod::HM_End))) { - pokemod->validationMsg("Invalid under tile"); + pokemod()->validationMsg("Invalid under tile"); valid = false; } - else if ((hmType == Pokemod::HM_RockClimb) && (!from[Pokemod::D_Up] || !from[Pokemod::D_Down])) + else if ((m_hmType == Pokemod::HM_RockClimb) && (!m_from[Pokemod::D_Up] || !m_from[Pokemod::D_Down])) { - pokemod->validationMsg("A rock climb tile must be accessible from above and below"); + pokemod()->validationMsg("A rock climb tile must be accessible from above and below"); valid = false; } - if (forceType < End) + if (m_forceType < End) { - if (((forceType == Slip) || (forceType == Force) || (forceType == Push)) && (Pokemod::D_End <= forceDirection)) + if (((m_forceType == Slip) || (m_forceType == Force) || (m_forceType == Push)) && (Pokemod::D_End <= m_forceDirection)) { - pokemod->validationMsg("Invalid force direction"); + pokemod()->validationMsg("Invalid force direction"); valid = false; } } else { - pokemod->validationMsg("Invalid force type"); + pokemod()->validationMsg("Invalid force type"); valid = false; } return valid; } -void Tile::load(const QString& fname, const int _id) throw(Exception) +void Tile::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name); - ini.getValue("from-up", from[Pokemod::D_Up], false); - ini.getValue("from-down", from[Pokemod::D_Down], false); - ini.getValue("from-left", from[Pokemod::D_Left], false); - ini.getValue("from-right", from[Pokemod::D_Right], false); + ini.getValue("name", m_name); + ini.getValue("from-up", m_from[Pokemod::D_Up], false); + ini.getValue("from-down", m_from[Pokemod::D_Down], false); + ini.getValue("from-left", m_from[Pokemod::D_Left], false); + ini.getValue("from-right", m_from[Pokemod::D_Right], false); ini.getValue("wildChance-n", i, 1); ini.getValue("wildChance-d", j, 1); - wildChance.set(i, j); - ini.getValue("hmType", hmType); - ini.getValue("under", under); - ini.getValue("forceType", forceType); - ini.getValue("forceDirection", forceDirection); + m_wildChance.set(i, j); + ini.getValue("hmType", m_hmType); + ini.getValue("under", m_under); + ini.getValue("forceType", m_forceType); + ini.getValue("forceDirection", m_forceDirection); } void Tile::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("from-up", from[Pokemod::D_Up]); - ini.addField("from-down", from[Pokemod::D_Down]); - ini.addField("from-left", from[Pokemod::D_Left]); - ini.addField("from-right", from[Pokemod::D_Right]); - ini.addField("wildChance-n", wildChance.getNum()); - ini.addField("wildChance-d", wildChance.getDenom()); - ini.addField("hmType", hmType); - ini.addField("under", under); - ini.addField("forceType", forceType); - ini.addField("forceDirection", forceDirection); - ini.save(QString("%1/tile/%2.pini").arg(pokemod->getPath()).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("from-up", m_from[Pokemod::D_Up]); + ini.addField("from-down", m_from[Pokemod::D_Down]); + ini.addField("from-left", m_from[Pokemod::D_Left]); + ini.addField("from-right", m_from[Pokemod::D_Right]); + ini.addField("wildChance-n", m_wildChance.numerator()); + ini.addField("wildChance-d", m_wildChance.denominator()); + ini.addField("hmType", m_hmType); + ini.addField("under", m_under); + ini.addField("forceType", m_forceType); + ini.addField("forceDirection", m_forceDirection); + ini.save(QString("%1/tile/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Tile::setName(const QString& n) +void Tile::setName(const QString& name) { - name = n; + m_name = name; } -void Tile::setPic(const QString& fname) throw(Exception) +void Tile::setPic(const QString& fileName) throw(Exception) { - QFile file(getPic()); + QFile file(pic()); if (file.exists() && !file.remove()) - throw(RemoveException(className, file.fileName())); - if (!QFile::copy(fname, getPic())) - throw(SaveException(className, file.fileName())); -} - -void Tile::setFrom(const int d, const bool f) throw(BoundsException) -{ - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - from[d] = f; -} - -void Tile::setWildChance(const int n, const int d) throw(Exception) -{ - wildChance.set(n, d); + throw(RemoveException(className(), file.fileName())); + if (!QFile::copy(fileName, pic())) + throw(SaveException(className(), file.fileName())); } -void Tile::setWildChanceNum(const int n) throw(Exception) +void Tile::setFrom(const int direction, const bool state) throw(BoundsException) { - wildChance.setNum(n); + if (Pokemod::D_End <= direction) + throw(BoundsException(className(), "direction")); + m_from[direction] = state; } -void Tile::setWildChanceDenom(const int d) throw(Exception) +void Tile::setWildChance(const int numerator, const int denominator) throw(Exception) { - wildChance.setDenom(d); + m_wildChance.set(numerator, denominator); } -void Tile::setHMType(const int h) throw(BoundsException) +void Tile::setHMType(const int hmType) throw(BoundsException) { - if (Pokemod::HM_End <= h) - throw(BoundsException(className, "hmType")); - hmType = h; - under = -1; + if (Pokemod::HM_End <= hmType) + throw(BoundsException(className(), "hmType")); + m_hmType = hmType; + m_under = INT_MAX; } -void Tile::setUnder(const int u) throw(Exception) +void Tile::setUnder(const int under) throw(Exception) { - if (hmType != -1) + if (m_hmType != INT_MAX) { - if ((hmType != Pokemod::HM_Whirlpool) || (hmType != Pokemod::HM_Cut) || (hmType != Pokemod::HM_RockSmash)) - throw(UnusedException(className, "under")); - if ((u == id) || (pokemod->getTileIndex(u) == -1)) - throw(BoundsException(className, "under")); + if ((m_hmType != Pokemod::HM_Whirlpool) || (m_hmType != Pokemod::HM_Cut) || (m_hmType != Pokemod::HM_RockSmash)) + throw(UnusedException(className(), "under")); + if ((under == id()) || (pokemod()->tileIndex(under) == INT_MAX)) + throw(BoundsException(className(), "under")); } - under = u; + m_under = under; } -void Tile::setForceType(const int f) throw(BoundsException) +void Tile::setForceType(const int forceType) throw(BoundsException) { - if (End <= f) - throw(BoundsException(className, "forceType")); - forceType = f; + if (End <= forceType) + throw(BoundsException(className(), "forceType")); + m_forceType = forceType; } -void Tile::setForceDirection(const int f) throw(Exception) +void Tile::setForceDirection(const int forceDirection) throw(Exception) { - if (forceType != -1) + if (m_forceType != INT_MAX) { - if (forceType == Stop) - throw(UnusedException(className, "forceDirection")); - if (Pokemod::D_End <= f) - throw(BoundsException(className, "forceDirection")); + if (m_forceType == Stop) + throw(UnusedException(className(), "forceDirection")); + if (Pokemod::D_End <= forceDirection) + throw(BoundsException(className(), "forceDirection")); } - forceDirection = f; + m_forceDirection = forceDirection; } -QString Tile::getName() const +QString Tile::name() const { - return name; + return m_name; } -QString Tile::getPic() const +QString Tile::pic() const { - return QString("%1/tile/%2.png").arg(pokemod->getPath()).arg(name); + return QString("%1/tile/%2.png").arg(pokemod()->path()).arg(m_name); } -bool Tile::getFrom(const int d) const throw(BoundsException) +bool Tile::from(const int direction) const throw(BoundsException) { - if (Pokemod::D_End <= d) - throw(BoundsException(className, "direction")); - return from[d]; + if (Pokemod::D_End <= direction) + throw(BoundsException(className(), "direction")); + return m_from[direction]; } -Frac Tile::getWildChance() const +Frac Tile::wildChance() const { - return wildChance; + return m_wildChance; } -int Tile::getHMType() const +int Tile::hmType() const { - return hmType; + return m_hmType; } -int Tile::getUnder() const +int Tile::under() const { - return under; + return m_under; } -int Tile::getForceType() const +int Tile::forceType() const { - return forceType; + return m_forceType; } -int Tile::getForceDirection() const +int Tile::forceDirection() const { - return forceDirection; + return m_forceDirection; } Tile& Tile::operator=(const Tile& rhs) { if (this == &rhs) return *this; - name = rhs.name; + m_name = rhs.m_name; for (int i = 0; i < Pokemod::D_End; ++i) - from[i] = rhs.from[i]; - wildChance = rhs.wildChance; - hmType = rhs.hmType; - under = rhs.under; - forceType = rhs.forceType; - forceDirection = rhs.forceDirection; + m_from[i] = rhs.m_from[i]; + m_wildChance = rhs.m_wildChance; + m_hmType = rhs.m_hmType; + m_under = rhs.m_under; + m_forceType = rhs.m_forceType; + m_forceDirection = rhs.m_forceDirection; return *this; } diff --git a/pokemod/Tile.h b/pokemod/Tile.h index f335a4ee..a330a666 100644 --- a/pokemod/Tile.h +++ b/pokemod/Tile.h @@ -1,34 +1,32 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Tile.h -// Purpose: Define a tile for the map -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Thu May 31 2007 13:28:49 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> #include <QStringList> +// General includes #include <Exception.h> #include <Frac.h> +// Pokemod includes #include "Object.h" #include "Pokemod.h" @@ -45,44 +43,42 @@ class Tile : public Object }; static const QStringList ForceStr; - Tile(const Pokemod* par, const int _id); - Tile(const Pokemod* par, const Tile& t, const int _id); - Tile(const Pokemod* par, const QString& fname, const int _id = -1); + Tile(const Pokemod* pokemod, const int id); + Tile(const Pokemod* pokemod, const Tile& tile, const int id); + Tile(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setPic(const QString& p) throw(Exception); - void setFrom(const int d, const bool f) throw(BoundsException); - void setWildChance(const int n, const int d) throw(Exception); - void setWildChanceNum(const int n) throw(Exception); - void setWildChanceDenom(const int d) throw(Exception); - void setHMType(const int h) throw(BoundsException); - void setUnder(const int u) throw(Exception); - void setForceType(const int f) throw(BoundsException); - void setForceDirection(const int f) throw(Exception); + void setName(const QString& name); + void setPic(const QString& fileName) throw(Exception); + void setFrom(const int direction, const bool state) throw(BoundsException); + void setWildChance(const int numerator, const int denominator) throw(Exception); + void setHMType(const int hmType) throw(BoundsException); + void setUnder(const int under) throw(Exception); + void setForceType(const int forceType) throw(BoundsException); + void setForceDirection(const int forceDirection) throw(Exception); - QString getName() const; - QString getPic() const; - bool getFrom(const int d) const throw(BoundsException); - Frac getWildChance() const; - int getHMType() const; - int getUnder() const; - int getForceType() const; - int getForceDirection() const; + QString name() const; + QString pic() const; + bool from(const int direction) const throw(BoundsException); + Frac wildChance() const; + int hmType() const; + int under() const; + int forceType() const; + int forceDirection() const; Tile& operator=(const Tile& rhs); private: bool validate() const; - QString name; - bool from[Pokemod::D_End]; - Frac wildChance; - int hmType; - int under; - int forceType; - int forceDirection; + QString m_name; + bool m_from[Pokemod::D_End]; + Frac m_wildChance; + int m_hmType; + int m_under; + int m_forceType; + int m_forceDirection; }; #endif diff --git a/pokemod/Time.cpp b/pokemod/Time.cpp index 3040ee38..6807903e 100644 --- a/pokemod/Time.cpp +++ b/pokemod/Time.cpp @@ -1,132 +1,126 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Time.cpp -// Purpose: Define the start of a time of day in the PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:00:46 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ #include "Pokemod.h" #include "Time.h" -Time::Time(const Pokemod* par, const int _id) : - Object("Time", par, _id), - name(""), - startHour(0), - startMinute(0) +Time::Time(const Pokemod* pokemod, const int id) : + Object("Time", pokemod, id), + m_name(""), + m_hour(0), + m_minute(0) { } -Time::Time(const Pokemod* par, const Time& t, const int _id) : - Object("Time", par, _id) +Time::Time(const Pokemod* pokemod, const Time& time, const int id) : + Object("Time", pokemod, id) { - *this = t; + *this = time; } -Time::Time(const Pokemod* par, const QString& fname, const int _id) : - Object("Time", par, _id) +Time::Time(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Time", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Time::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Time \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Time \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name not defined"); + pokemod()->validationMsg("Name not defined"); valid = false; } - if (23 < startHour) + if (23 < m_hour) { - pokemod->validationMsg("Invalid starting hour"); + pokemod()->validationMsg("Invalid starting hour"); valid = false; } - if (59 < startMinute) + if (59 < m_minute) { - pokemod->validationMsg("Invalid start minute"); + pokemod()->validationMsg("Invalid start minute"); valid = false; } return valid; } -void Time::load(const QString& fname, const int _id) throw(Exception) +void Time::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name, ""); - ini.getValue("startHour", startHour, 0); - ini.getValue("startMinute", startMinute, 0); + setId(id); + ini.getValue("name", m_name); + ini.getValue("hour", m_hour, 0); + ini.getValue("minute", m_minute, 0); } void Time::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("startHour", startHour); - ini.addField("startMinute", startMinute); - ini.save(QString("%1/time/%2.pini").arg(pokemod->getPath()).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("hour", m_hour); + ini.addField("minute", m_minute); + ini.save(QString("%1/time/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Time::setName(const QString& n) +void Time::setName(const QString& name) { - name = n; + m_name = name; } -void Time::setStartHour(const int h) throw(BoundsException) +void Time::setHour(const int hour) throw(BoundsException) { - if (24 <= h) - throw(BoundsException(className, "startHour")); - startHour = h; + if (24 <= hour) + throw(BoundsException(className(), "hour")); + m_hour = hour; } -void Time::setStartMinute(const int m) throw(BoundsException) +void Time::setMinute(const int minute) throw(BoundsException) { - if (60 <= m) - throw(BoundsException(className, "startMinute")); - startMinute = m; + if (60 <= minute) + throw(BoundsException(className(), "minute")); + m_minute = minute; } -QString Time::getName() const +QString Time::name() const { - return name; + return m_name; } -int Time::getStartHour() const +int Time::hour() const { - return startHour; + return m_hour; } -int Time::getStartMinute() const +int Time::minute() const { - return startMinute; + return m_minute; } Time& Time::operator=(const Time& rhs) { if (this == &rhs) return *this; - name = rhs.name; - startHour = rhs.startHour; - startMinute = rhs.startMinute; + m_name = rhs.m_name; + m_hour = rhs.m_hour; + m_minute = rhs.m_minute; return *this; } diff --git a/pokemod/Time.h b/pokemod/Time.h index 10212ce9..c8c3a4b2 100644 --- a/pokemod/Time.h +++ b/pokemod/Time.h @@ -1,61 +1,60 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Time.h -// Purpose: Define the start of a time of day in the PokéMod -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Wed Feb 28 21:00:46 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class Time : public Object { public: - Time(const Pokemod* par, const int _id); - Time(const Pokemod* par, const Time& t, const int _id); - Time(const Pokemod* par, const QString& fname, const int _id = -1); + Time(const Pokemod* pokemod, const int id); + Time(const Pokemod* pokemod, const Time& time, const int id); + Time(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setStartHour(const int h) throw(BoundsException); - void setStartMinute(const int m) throw(BoundsException); + void setName(const QString& name); + void setHour(const int hour) throw(BoundsException); + void setMinute(const int minutes) throw(BoundsException); - QString getName() const; - int getStartHour() const; - int getStartMinute() const; + QString name() const; + int hour() const; + int minute() const; Time& operator=(const Time& rhs); private: bool validate() const; - QString name; - int startHour; - int startMinute; + QString m_name; + int m_hour; + int m_minute; }; #endif diff --git a/pokemod/Trainer.cpp b/pokemod/Trainer.cpp index f82660a1..6981c67d 100644 --- a/pokemod/Trainer.cpp +++ b/pokemod/Trainer.cpp @@ -1,149 +1,143 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Trainer.cpp -// Purpose: Define a type of trainer -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sat Mar 8 16:30:03 2008 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ #include "Pokemod.h" #include "Trainer.h" -Trainer::Trainer(const Pokemod* par, const int _id) : - Object("Trainer", par, _id), - name(""), - moneyFactor(0) +Trainer::Trainer(const Pokemod* pokemod, const int id) : + Object("Trainer", pokemod, id), + m_name(""), + m_moneyFactor(0) { } -Trainer::Trainer(const Pokemod* par, const Trainer& t, const int _id) : - Object("Trainer", par, _id) +Trainer::Trainer(const Pokemod* pokemod, const Trainer& trainer, const int id) : + Object("Trainer", pokemod, id) { - *this = t; + *this = trainer; } -Trainer::Trainer(const Pokemod* par, const QString& fname, const int _id) : - Object("Trainer", par, _id) +Trainer::Trainer(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Trainer", pokemod, id) { - load(fname); + load(fileName); } bool Trainer::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Trainer \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Trainer \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("Name not defined"); + pokemod()->validationMsg("Name not defined"); valid = false; } - if (moneyFactor < 0) + if (m_moneyFactor < 0) { - pokemod->validationMsg("Invalid money factor"); + pokemod()->validationMsg("Invalid money factor"); valid = false; } - if (!QFile(getSkin()).exists()) + if (!QFile(skin()).exists()) { - pokemod->validationMsg("Cannot find the skin"); + pokemod()->validationMsg("Cannot find the skin"); valid = false; } - if (!QFile(getAi()).exists()) + if (!QFile(ai()).exists()) { - pokemod->validationMsg("Cannot find the AI file"); + pokemod()->validationMsg("Cannot find the AI file"); valid = false; } return valid; } -void Trainer::load(const QString& fname, const int _id) throw(Exception) +void Trainer::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; - ini.getValue("name", name); - ini.getValue("moneyFactor", moneyFactor); + setId(id); + ini.getValue("name", m_name); + ini.getValue("moneyFactor", m_moneyFactor); } void Trainer::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("moneyFactor", moneyFactor); - ini.save(QString("%1/trainer/%2/data.pini").arg(pokemod->getPath()).arg(name)); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("moneyFactor", m_moneyFactor); + ini.save(QString("%1/trainer/%2/data.pini").arg(pokemod()->path()).arg(m_name)); } -void Trainer::setName(const QString& n) +void Trainer::setName(const QString& name) { - name = n; + m_name = name; } -void Trainer::setMoneyFactor(const int m) throw(BoundsException) +void Trainer::setMoneyFactor(const int moneyFactor) throw(BoundsException) { - if (m < 0) - throw(BoundsException(className, "moneyFactor")); - moneyFactor = m; + if (moneyFactor < 0) + throw(BoundsException(className(), "moneyFactor")); + m_moneyFactor = moneyFactor; } -void Trainer::setSkin(const QString& s) throw(Exception) +void Trainer::setSkin(const QString& fileName) throw(Exception) { - QFile file(getSkin()); + QFile file(skin()); if (file.exists() && !file.remove()) - throw(ReplaceException(className, file.fileName())); - if (!QFile::copy(s, getSkin())) - throw(SaveException(className, file.fileName())); + throw(ReplaceException(className(), file.fileName())); + if (!QFile::copy(fileName, skin())) + throw(SaveException(className(), file.fileName())); } -void Trainer::setAi(const QString& a) throw(Exception) +void Trainer::setAi(const QString& fileName) throw(Exception) { - QFile file(getAi()); + QFile file(ai()); if (file.exists() && !file.remove()) - throw(ReplaceException(className, file.fileName())); - if (!QFile::copy(a, getAi())) - throw(SaveException(className, file.fileName())); + throw(ReplaceException(className(), file.fileName())); + if (!QFile::copy(fileName, ai())) + throw(SaveException(className(), file.fileName())); } -QString Trainer::getName() const +QString Trainer::name() const { - return name; + return m_name; } -int Trainer::getMoneyFactor() const +int Trainer::moneyFactor() const { - return moneyFactor; + return m_moneyFactor; } -QString Trainer::getSkin() const +QString Trainer::skin() const { - return QString("%1/trainer/%2/skin.png").arg(pokemod->getPath()).arg(name); + return QString("%1/trainer/%2/skin.png").arg(pokemod()->path()).arg(m_name); } -QString Trainer::getAi() const +QString Trainer::ai() const { - return QString("%1/badge/%2/ai.pai").arg(pokemod->getPath()).arg(name); + return QString("%1/trainer/%2/ai.pai").arg(pokemod()->path()).arg(m_name); } Trainer& Trainer::operator=(const Trainer& rhs) { if (this == &rhs) return *this; - name = rhs.name; - moneyFactor = rhs.moneyFactor; + m_name = rhs.m_name; + m_moneyFactor = rhs.m_moneyFactor; return *this; } diff --git a/pokemod/Trainer.h b/pokemod/Trainer.h index 715fb565..5b23fcdc 100644 --- a/pokemod/Trainer.h +++ b/pokemod/Trainer.h @@ -1,60 +1,58 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Trainer.h -// Purpose: Define a type of trainer -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Sat Mar 8 15:53:15 2008 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// General includes #include <Exception.h> +// Pokemod includes #include "Object.h" +// Forward declarations class Pokemod; class Trainer : public Object { public: - Trainer(const Pokemod* par, const int _id); - Trainer(const Pokemod* par, const Trainer& t, const int _id); - Trainer(const Pokemod* par, const QString& fname, const int _id = -1); + Trainer(const Pokemod* pokemod, const int id); + Trainer(const Pokemod* pokemod, const Trainer& trainer, const int id); + Trainer(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setMoneyFactor(const int m) throw(BoundsException); - void setSkin(const QString& s) throw(Exception); - void setAi(const QString& a) throw(Exception); + void setName(const QString& name); + void setMoneyFactor(const int moneyFactor) throw(BoundsException); + void setSkin(const QString& fileName) throw(Exception); + void setAi(const QString& fileName) throw(Exception); - QString getName() const; - int getMoneyFactor() const; - QString getSkin() const; - QString getAi() const; + QString name() const; + int moneyFactor() const; + QString skin() const; + QString ai() const; Trainer& operator=(const Trainer& rhs); private: bool validate() const; - QString name; - int moneyFactor; + QString m_name; + int m_moneyFactor; }; #endif diff --git a/pokemod/Type.cpp b/pokemod/Type.cpp index c4cbf4f1..62d47461 100644 --- a/pokemod/Type.cpp +++ b/pokemod/Type.cpp @@ -1,119 +1,106 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Type.cpp -// Purpose: Define a type for a species -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:05:05 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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/>. + */ +// Pokemod includes #include "Pokemod.h" + +// Header includes #include "Type.h" -Type::Type(const Pokemod* par, const int _id) : - Object("Type", par, _id), - name(""), - stab(1, 1, true) +Type::Type(const Pokemod* pokemod, const int id) : + Object("Type", pokemod, id), + m_name(""), + m_stab(1, 1, true) { } -Type::Type(const Pokemod* par, const Type& t, const int _id) : - Object("Type", par, _id) +Type::Type(const Pokemod* pokemod, const Type& type, const int id) : + Object("Type", pokemod, id) { - *this = t; + *this = type; } -Type::Type(const Pokemod* par, const QString& fname, const int _id) : - Object("Type", par, _id) +Type::Type(const Pokemod* pokemod, const QString& fileName, const int id) : + Object("Type", pokemod, id) { - load(fname, _id); + load(fileName, id); } bool Type::validate() const { bool valid = true; - pokemod->validationMsg(QString("---Type \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); - if (name == "") + pokemod()->validationMsg(QString("---Type \"%1\" with id %2---").arg(m_name).arg(id()), Pokemod::V_Msg); + if (m_name == "") { - pokemod->validationMsg("No name defined"); + pokemod()->validationMsg("No name defined"); valid = false; } return valid; } -void Type::load(const QString& fname, const int _id) throw(Exception) +void Type::load(const QString& fileName, int id) throw(Exception) { - Ini ini(fname); - if (_id == -1) + Ini ini(fileName); + if (id == INT_MAX) ini.getValue("id", id); - else - id = _id; + setId(id); int i; int j; - ini.getValue("name", name, ""); + ini.getValue("name", m_name, ""); ini.getValue("stab-n", i, 1); ini.getValue("stab-d", j, 1); - stab.set(i, j, true); + m_stab.set(i, j, true); } void Type::save() const throw(Exception) { Ini ini; - ini.addField("id", id); - ini.addField("name", name); - ini.addField("stab-n", stab.getNum()); - ini.addField("stab-d", stab.getDenom()); - ini.save(QString("%1/type/%2.pini").arg(pokemod->getPath()).arg(name)); -} - -void Type::setName(const QString& n) -{ - name = n; -} - -void Type::setStab(const int n, const int d) throw(Exception) -{ - stab.set(n, d); + ini.addField("id", id()); + ini.addField("name", m_name); + ini.addField("stab-n", m_stab.numerator()); + ini.addField("stab-d", m_stab.denominator()); + ini.save(QString("%1/type/%2.pini").arg(pokemod()->path()).arg(m_name)); } -void Type::setStabNum(const int n) throw(Exception) +void Type::setName(const QString& name) { - stab.setNum(n); + m_name = name; } -void Type::setStabDenom(const int d) throw(Exception) +void Type::setStab(const int numerator, const int denominator) throw(Exception) { - stab.setDenom(d); + m_stab.set(numerator, denominator); } -QString Type::getName() const +QString Type::name() const { - return name; + return m_name; } -Frac Type::getStab() const +Frac Type::stab() const { - return stab; + return m_stab; } Type& Type::operator=(const Type& rhs) { if (this == &rhs) return *this; - name = rhs.name; - stab = rhs.stab; + m_name = rhs.m_name; + m_stab = rhs.m_stab; return *this; } diff --git a/pokemod/Type.h b/pokemod/Type.h index b9938f65..8314d74b 100644 --- a/pokemod/Type.h +++ b/pokemod/Type.h @@ -1,60 +1,60 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokemod/Type.h -// Purpose: Define a type for species and moves -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Tue Mar 20 18:05:05 2007 -// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions -// Licence: -// 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/>. -///////////////////////////////////////////////////////////////////////////// +/* + * 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__ +// Qt includes #include <QString> +// General includes #include <Frac.h> +// Pokemod includes #include "Object.h" - -class Pokemod; +#include "Pokemod.h" class Type : public Object { public: - Type(const Pokemod* par, const int _id); - Type(const Pokemod* par, const Type& t, const int _id); - Type(const Pokemod* par, const QString& fname, const int _id = -1); + Type(const Pokemod* pokemod, const int id); + Type(const Pokemod* pokemod, const Type& type, const int id); + Type(const Pokemod* pokemod, const QString& fileName, const int id = INT_MAX); - void load(const QString& fname, const int _id = -1) throw(Exception); + void load(const QString& fileName, const int id = INT_MAX) throw(Exception); void save() const throw(Exception); - void setName(const QString& n); - void setStab(const int n, const int d) throw(Exception); - void setStabNum(const int n) throw(Exception); - void setStabDenom(const int d) throw(Exception); + void setName(const QString& name); + void setStab(const int numerator, const int denominator) throw(Exception); + void setStabNumerator(const int numerator) throw(Exception); + void setStabDenominator(const int denominator) throw(Exception); + void setImmunity(const int status, const bool immune) throw(BoundsException); - QString getName() const; - Frac getStab() const; + QString name() const; + Frac stab() const; + bool immunity(const int status) const throw(BoundsException); Type& operator=(const Type& rhs); private: bool validate() const; - QString name; - Frac stab; + QString m_name; + Frac m_stab; + bool m_immunity[Pokemod::STS_End]; }; #endif diff --git a/pokemodr/FileDialog.cpp b/pokemodr/FileDialog.cpp index 09afd852..858fbaab 100644 --- a/pokemodr/FileDialog.cpp +++ b/pokemodr/FileDialog.cpp @@ -30,6 +30,8 @@ #include "FileDialog.h" +KUrl FileDialog::latestDir = KUrl(); + FileDialog::FileDialog(const QString& filter, const QSize& imgSize) : QObject(NULL), dlg(NULL) diff --git a/pokemodr/FileDialog.h b/pokemodr/FileDialog.h index 4b60dac0..0057e64e 100644 --- a/pokemodr/FileDialog.h +++ b/pokemodr/FileDialog.h @@ -60,7 +60,7 @@ class FileDialog : public QObject KFileDialog* dlg; QSize size; QString url; - KUrl latestDir; + static KUrl latestDir; }; #endif diff --git a/pokemodr/MapUI.cpp b/pokemodr/MapUI.cpp index a5fc93bf..a9760c28 100644 --- a/pokemodr/MapUI.cpp +++ b/pokemodr/MapUI.cpp @@ -71,7 +71,7 @@ void MapUI::refreshGui() void MapUI::setGui() { varName->setText(map_mod->getName()); - boxFlyWarp->setChecked((map_mod->getFlyWarp() == -1) ? Qt::Unchecked : Qt::Checked); + boxFlyWarp->setChecked((map_mod->getFlyWarp() == INT_MAX) ? Qt::Unchecked : Qt::Checked); varFlyWarp->setCurrentIndex(varFlyWarp->findData(map_mod->getFlyWarp())); varType->setCurrentIndex(map_mod->getType()); } diff --git a/pokemodr/MapWarpUI.cpp b/pokemodr/MapWarpUI.cpp index 341ccbd0..01364df7 100644 --- a/pokemodr/MapWarpUI.cpp +++ b/pokemodr/MapWarpUI.cpp @@ -87,7 +87,7 @@ void MapWarpUI::setGui() { varToWarp->clear(); int index = mapWarp->getPokemod()->getMapIndex(mapWarp_mod->getToMap()); - if (index != -1) + if (index != INT_MAX) { try { diff --git a/pokemodr/MapWildListUI.cpp b/pokemodr/MapWildListUI.cpp index 86a66e4b..df0d2ee6 100644 --- a/pokemodr/MapWildListUI.cpp +++ b/pokemodr/MapWildListUI.cpp @@ -93,7 +93,7 @@ void MapWildListUI::setGui() QListWidgetItem* lwi = varTimes->item(i); lwi->setSelected(mapWildList_mod->getTime(lwi->data(Qt::UserRole).toInt())); } - boxScope->setChecked(mapWildList_mod->getScope() == -1); + boxScope->setChecked(mapWildList_mod->getScope() == INT_MAX); varScope->setCurrentIndex(varScope->findData(mapWildList_mod->getScope())); } @@ -159,7 +159,7 @@ void MapWildListUI::on_varTimes_itemSelectionChanged() void MapWildListUI::on_boxScope_toggled(const bool s) { if (!s) - mapWildList_mod->setScope(-1); + mapWildList_mod->setScope(INT_MAX); emit(changed(true)); setGui(); } diff --git a/pokemodr/PokemodUI.cpp b/pokemodr/PokemodUI.cpp index ac3c987b..57ec83ea 100644 --- a/pokemodr/PokemodUI.cpp +++ b/pokemodr/PokemodUI.cpp @@ -83,7 +83,7 @@ void PokemodUI::setGui() { varWarp->clear(); int index = pokemod->getMapIndex(pokemod_mod->getStartMap()); - if (index != -1) + if (index != INT_MAX) { try { diff --git a/pokemodr/SpeciesUI.cpp b/pokemodr/SpeciesUI.cpp index 2ef67362..1c147d29 100644 --- a/pokemodr/SpeciesUI.cpp +++ b/pokemodr/SpeciesUI.cpp @@ -165,7 +165,7 @@ void SpeciesUI::setGui() catch (OpenException& e) { } - boxGenderChance->setChecked(species_mod->getGenderFactor().getNum() == -1); + boxGenderChance->setChecked(species_mod->getGenderFactor().getNum() == INT_MAX); varGenderChanceNum->setValue(species_mod->getGenderFactor().getNum()); varGenderChanceDenom->setValue(species_mod->getGenderFactor().getDenom()); varGenderChanceNum->setMaximum(species_mod->getGenderFactor().getDenom()); @@ -452,7 +452,7 @@ void SpeciesUI::on_varListSprite_pressed() void SpeciesUI::on_boxGenderChance_toggled(const bool g) { - species_mod->setGenderFactor(g ? 1 : -1, 1); + species_mod->setGenderFactor(g ? 1 : INT_MAX, 1); emit(changed(true)); setGui(); } diff --git a/pokemodr/TODO b/pokemodr/TODO index 2519245d..ec295589 100644 --- a/pokemodr/TODO +++ b/pokemodr/TODO @@ -4,5 +4,3 @@ ItemEffect MapEffect MapTrainer MoveEffect - -Toolbar loading diff --git a/pokemodr/TileUI.cpp b/pokemodr/TileUI.cpp index 15fa59cc..7b910e17 100644 --- a/pokemodr/TileUI.cpp +++ b/pokemodr/TileUI.cpp @@ -85,11 +85,11 @@ void TileUI::setGui() varWildDenom->setValue(tile_mod->getWildChance().getDenom()); varWildNum->setMaximum(tile_mod->getWildChance().getDenom()); varWild->setText(QString::number(tile_mod->getWildChance(), 'g', DBL_PREC)); - boxHMs->setChecked((tile_mod->getHMType() == -1) ? Qt::Unchecked : Qt::Checked); + boxHMs->setChecked((tile_mod->getHMType() == INT_MAX) ? Qt::Unchecked : Qt::Checked); varHMType->setCurrentIndex(tile_mod->getHMType()); varHMUnder->setCurrentIndex(varHMUnder->findData(tile_mod->getUnder())); varHMUnder->setEnabled((tile_mod->getHMType() == Pokemod::HM_Whirlpool) || (tile_mod->getHMType() == Pokemod::HM_Cut) || (tile_mod->getHMType() == Pokemod::HM_RockSmash)); - boxForces->setChecked((tile_mod->getForceType() == -1) ? Qt::Unchecked : Qt::Checked); + boxForces->setChecked((tile_mod->getForceType() == INT_MAX) ? Qt::Unchecked : Qt::Checked); varForce->setCurrentIndex(tile_mod->getForceType()); varDirection->setCurrentIndex(tile_mod->getForceDirection()); varDirection->setEnabled((tile_mod->getForceType() != Tile::Stop) && (tile_mod->getForceType() != Tile::Slip)); diff --git a/pokemodr/TilemapModel.cpp b/pokemodr/TilemapModel.cpp index 683420cd..1e4e8ec5 100644 --- a/pokemodr/TilemapModel.cpp +++ b/pokemodr/TilemapModel.cpp @@ -54,7 +54,7 @@ QVariant TilemapModel::data(const QModelIndex& index, int role) const if (role == Qt::DisplayRole) { int idx = pokemod->getTileIndex(map->at(index.row(), index.column())); - if (idx != -1) + if (idx != INT_MAX) return ImageCache::open(pokemod->getTile(idx)->getPic()); } if (role == Qt::EditRole) @@ -62,7 +62,7 @@ QVariant TilemapModel::data(const QModelIndex& index, int role) const if (role == Qt::ToolTipRole) { int idx = pokemod->getTileIndex(map->at(index.row(), index.column())); - if (idx != -1) + if (idx != INT_MAX) return pokemod->getTile(idx)->getName(); } return QVariant(); |
