diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-03-09 22:20:15 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-03-09 22:20:15 +0000 |
| commit | 0191933210bd20a59527fcf2732a4f3c846fb2a9 (patch) | |
| tree | 4779040481aabbe121cf50286a0ad2f5a316c70e /pokemod/Trainer.cpp | |
| parent | 68447b2a21c928526b2a7e614a1d56484f379bc6 (diff) | |
| download | sigen-0191933210bd20a59527fcf2732a4f3c846fb2a9.tar.gz sigen-0191933210bd20a59527fcf2732a4f3c846fb2a9.tar.xz sigen-0191933210bd20a59527fcf2732a4f3c846fb2a9.zip | |
[ADD] ItemType now has a count descriptor
[ADD] Species now has a flee chance
[FIX] Empty fields removed from .ui files
[FIX] Fixed compile errors in pokemodr
[ADD] Trainer now helps to simplify MapTrainers
[ADD] Trainer UI file
[FIX] MapTrainer dialogs condensed
[FIX] Home direcotry now gotten by QDir::homePath() rather than ~
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@93 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Trainer.cpp')
| -rw-r--r-- | pokemod/Trainer.cpp | 149 |
1 files changed, 149 insertions, 0 deletions
diff --git a/pokemod/Trainer.cpp b/pokemod/Trainer.cpp new file mode 100644 index 00000000..f82660a1 --- /dev/null +++ b/pokemod/Trainer.cpp @@ -0,0 +1,149 @@ +///////////////////////////////////////////////////////////////////////////// +// 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/>. +///////////////////////////////////////////////////////////////////////////// + +#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* par, const Trainer& t, const int _id) : + Object("Trainer", par, _id) +{ + *this = t; +} + +Trainer::Trainer(const Pokemod* par, const QString& fname, const int _id) : + Object("Trainer", par, _id) +{ + load(fname); +} + +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("Name not defined"); + valid = false; + } + if (moneyFactor < 0) + { + pokemod->validationMsg("Invalid money factor"); + valid = false; + } + if (!QFile(getSkin()).exists()) + { + pokemod->validationMsg("Cannot find the skin"); + valid = false; + } + if (!QFile(getAi()).exists()) + { + pokemod->validationMsg("Cannot find the AI file"); + valid = false; + } + return valid; +} + +void Trainer::load(const QString& fname, const int _id) throw(Exception) +{ + Ini ini(fname); + if (_id == -1) + ini.getValue("id", id); + else + id = _id; + ini.getValue("name", name); + ini.getValue("moneyFactor", 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)); +} + +void Trainer::setName(const QString& n) +{ + name = n; +} + +void Trainer::setMoneyFactor(const int m) throw(BoundsException) +{ + if (m < 0) + throw(BoundsException(className, "moneyFactor")); + moneyFactor = m; +} + +void Trainer::setSkin(const QString& s) throw(Exception) +{ + QFile file(getSkin()); + if (file.exists() && !file.remove()) + throw(ReplaceException(className, file.fileName())); + if (!QFile::copy(s, getSkin())) + throw(SaveException(className, file.fileName())); +} + +void Trainer::setAi(const QString& a) throw(Exception) +{ + QFile file(getAi()); + if (file.exists() && !file.remove()) + throw(ReplaceException(className, file.fileName())); + if (!QFile::copy(a, getAi())) + throw(SaveException(className, file.fileName())); +} + +QString Trainer::getName() const +{ + return name; +} + +int Trainer::getMoneyFactor() const +{ + return moneyFactor; +} + +QString Trainer::getSkin() const +{ + return QString("%1/trainer/%2/skin.png").arg(pokemod->getPath()).arg(name); +} + +QString Trainer::getAi() const +{ + return QString("%1/badge/%2/ai.pai").arg(pokemod->getPath()).arg(name); +} + +Trainer& Trainer::operator=(const Trainer& rhs) +{ + if (this == &rhs) + return *this; + name = rhs.name; + moneyFactor = rhs.moneyFactor; + return *this; +} |
