diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2007-10-26 20:46:09 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2007-10-26 20:46:09 +0000 |
| commit | 4385af885daf460a18e236f08509358f764b2c8c (patch) | |
| tree | 6c2838312dd7f42769280e24e8abc16b53c165cb /pokemod/Status.cpp | |
| parent | 1f08afc80c73087bf9bde639754670548b89fc9f (diff) | |
| download | sigen-4385af885daf460a18e236f08509358f764b2c8c.tar.gz sigen-4385af885daf460a18e236f08509358f764b2c8c.tar.xz sigen-4385af885daf460a18e236f08509358f764b2c8c.zip | |
Reverted repo back to rev24 because committing of rev25 messed up
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@26 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemod/Status.cpp')
| -rw-r--r-- | pokemod/Status.cpp | 259 |
1 files changed, 259 insertions, 0 deletions
diff --git a/pokemod/Status.cpp b/pokemod/Status.cpp new file mode 100644 index 00000000..7ea407e8 --- /dev/null +++ b/pokemod/Status.cpp @@ -0,0 +1,259 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: pokemod/Status.cpp +// Purpose: Define an Status that Pokémon can possess to add extra +// dynamics to the battle system +// Author: Ben Boeckel +// Modified by: Ben Boeckel +// Created: Sat June 2 2007 12:00:45 +// Copyright: ©2007 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 +// MERCHANTStatus 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 "Status.h" + +PokeGen::PokeMod::Status::Status(const Pokemod* par, const unsigned _id) : + Object(_id, par), + name(""), + abbreviation(""), + verb(""), + afterSwitch(UINT_MAX), + afterBattle(UINT_MAX), + maxTurns(0), + catchBonus(0) +{ +} + +PokeGen::PokeMod::Status::Status(const Pokemod* par, Ini& ini, const unsigned _id) : + Object(_id, par) +{ + ImportIni(ini, _id); +} + +bool PokeGen::PokeMod::Status::Validate() +{ + pokemod->ValidationMsg(QString("---Status \"%1\" with id %2---").arg(name).arg(id), Pokemod::V_Msg); + if (name == "") + { + pokemod->ValidationMsg("Name is not defined"); + isValid = false; + } + else if ((name == "Clear") || (name == "Any")) + { + pokemod->ValidationMsg("Invalid name"); + isValid = false; + } + if (abbreviation == "") + pokemod->ValidationMsg("Abbreviation is not defined"); + else if (4 <= abbreviation.length()) + { + pokemod->ValidationMsg("Abbreviation too long"); + isValid = false; + } + if (verb == "") + pokemod->ValidationMsg("Verb is not defined", Pokemod::V_Warn); + if (afterSwitch == UINT_MAX) + pokemod->ValidationMsg("After switch status is not defined", Pokemod::V_Warn); + else if (pokemod->GetStatusByID(afterSwitch) == UINT_MAX) + { + pokemod->ValidationMsg("Invalid after switch status"); + isValid = false; + } + if (afterBattle == UINT_MAX) + pokemod->ValidationMsg("After battle status is not defined", Pokemod::V_Warn); + else if (pokemod->GetStatusByID(afterBattle) == UINT_MAX) + { + pokemod->ValidationMsg("Invalid after battle abbreviation"); + isValid = false; + } + if (GetEffectCount()) + { + QMap<unsigned, unsigned> idChecker; + for (QList<StatusEffect>::Iterator i = effects.begin(); i != effects.end(); ++i) + { + if (!i->IsValid()) + isValid = false; + ++idChecker[i->GetId()]; + } + for (QMap<unsigned, unsigned>::ConstIterator i = idChecker.begin(); i != idChecker.end(); ++i) + { + if (1 < i.value()) + { + pokemod->ValidationMsg(QString("There are %1 effects with id %2").arg(i.value()).arg(i.key())); + isValid = false; + } + } + } + else + { + pokemod->ValidationMsg("There are no effects"); + isValid = false; + } + return isValid; +} + +void PokeGen::PokeMod::Status::ImportIni(Ini& ini, const unsigned _id) +{ + if (_id == UINT_MAX) + ini.GetValue("id", id); + else + id = _id; + ini.GetValue("name", name); + ini.GetValue("abbreviation", abbreviation); + ini.GetValue("verb", verb); + ini.GetValue("afterSwitch", afterSwitch); + ini.GetValue("afterBattle", afterBattle); + ini.GetValue("maxTurns", maxTurns, 0); + ini.GetValue("catchBonus", catchBonus, 0); + effects.clear(); +} + +void PokeGen::PokeMod::Status::ExportIni(QFile& fout) const +{ + Ini exStatus("Status"); + exStatus.AddField("id", id); + exStatus.AddField("name", name); + exStatus.AddField("abbreviation", abbreviation); + exStatus.AddField("verb", verb); + exStatus.AddField("afterSwitch", afterSwitch); + exStatus.AddField("afterBattle", afterBattle); + exStatus.AddField("maxTurns", maxTurns); + exStatus.AddField("catchBonus", catchBonus); + exStatus.Export(fout); + for (QList<StatusEffect>::ConstIterator i = effects.begin(); i != effects.end(); ++i) + i->ExportIni(fout, name); +} + +void PokeGen::PokeMod::Status::SetName(const QString& n) +{ + name = n; +} + +bool PokeGen::PokeMod::Status::SetAbbreviation(const QString& a) +{ + if (a.length() < 4) + abbreviation = a; + return (abbreviation == a); +} + +void PokeGen::PokeMod::Status::SetVerb(const QString& v) +{ + verb = v; +} + +bool PokeGen::PokeMod::Status::SetAfterSwitch(const unsigned a) +{ + if ((a == UINT_MAX) || (pokemod->GetStatusByID(a) != UINT_MAX)) + afterSwitch = a; + return (afterSwitch == a); +} + +bool PokeGen::PokeMod::Status::SetAfterBattle(const unsigned a) +{ + if ((a == UINT_MAX) || (pokemod->GetStatusByID(a) != UINT_MAX)) + afterBattle = a; + return (afterBattle == a); +} + +void PokeGen::PokeMod::Status::SetMaxTurns(const unsigned m) +{ + maxTurns = m; +} + +void PokeGen::PokeMod::Status::SetCatchBonus(const unsigned c) +{ + catchBonus = c; +} + +QString PokeGen::PokeMod::Status::GetName() const +{ + return name; +} + +QString PokeGen::PokeMod::Status::GetAbbreviation() const +{ + return abbreviation; +} + +QString PokeGen::PokeMod::Status::GetVerb() const +{ + return verb; +} + +unsigned PokeGen::PokeMod::Status::GetAfterSwitch() const +{ + return afterSwitch; +} + +unsigned PokeGen::PokeMod::Status::GetAfterBattle() const +{ + return afterBattle; +} + +unsigned PokeGen::PokeMod::Status::GetMaxTurns() const +{ + return maxTurns; +} + +unsigned PokeGen::PokeMod::Status::GetCatchBonus() const +{ + return catchBonus; +} + +const PokeGen::PokeMod::StatusEffect* PokeGen::PokeMod::Status::GetEffect(const unsigned i) const +{ + if (i < GetEffectCount()) + return &effects[i]; + return NULL; +} + +unsigned PokeGen::PokeMod::Status::GetEffectByID(const unsigned _id) const +{ + for (unsigned i = 0; i < GetEffectCount(); ++i) + { + if (effects[i].GetId() == _id) + return i; + } + return UINT_MAX; +} + +unsigned PokeGen::PokeMod::Status::GetEffectCount() const +{ + return effects.size(); +} + +const PokeGen::PokeMod::StatusEffect* PokeGen::PokeMod::Status::NewEffect(Ini* const ini) +{ + unsigned i = 0; + for (; i < GetEffectCount(); ++i) + { + if (GetEffectByID(i) != UINT_MAX) + break; + } + StatusEffect newEffect(pokemod, i); + if (ini) + newEffect.ImportIni(*ini); + effects.append(newEffect); + return &effects[GetEffectCount() - 1]; +} + +bool PokeGen::PokeMod::Status::DeleteEffect(const unsigned i) +{ + if (i < GetEffectCount()) + { + effects.erase(effects.begin() + i); + return true; + } + return false; +} |
